没有为参数1指定值

没有为参数1指定值

本文介绍了没有为参数1指定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编译时出现以下错误:没有为参数1指定值
我知道我应该添加一个像ps.setString(1,?)这样的句子,但是我应该输入什么值?我的菜单表中有两行.

When I compile, I get this error: No value specified for parameter 1
I know I should add a sentence like ps.setString(1, ?) but what is the value should I put? I have two row in my menu table.

public void CosineSimilarity( ArrayList<Integer> h) throws Exception {
     int[] vec1 =  h.stream().mapToInt(t -> t).toArray();
    String sql="Select Budget,Day from menu where M_ID=?";
    DatabaseConnection db = new DatabaseConnection();
    Connection  conn =db.getConnection();

    PreparedStatement  ps = conn.prepareStatement(sql);
    ArrayList<String> vector=new ArrayList<String>();

    vector.add("Budget");
    vector.add("Day");

    ResultSet rs = ps.executeQuery();
    ArrayList<Double> value  = new ArrayList<Double>();
    while (rs.next())
    {
        ArrayList<Integer> r=new ArrayList<Integer>();

        r.add(rs.getInt("Budget"));
        r.add(rs.getInt("Day"));

        int vec2[] = r.stream().mapToInt(t -> t).toArray();
        double cos_sim=cosine_similarity(vec1,vec2);
        value.add(cos_sim);
    }

    pick_highest_value_here_and_display(value);
    ps.close();
    rs.close();
    conn.close();


}

推荐答案

public void CosineSimilarity( ArrayList<Integer> h) throws Exception {
     int[] vec1 =  h.stream().mapToInt(t -> t).toArray();
    String sql="Select Budget,Day from menu ;
    DatabaseConnection db = new DatabaseConnection();
    Connection  conn =db.getConnection();

    PreparedStatement  ps = conn.prepareStatement(sql);
    ArrayList<String> vector=new ArrayList<String>();

    vector.add("Budget");
    vector.add("Day");

    ResultSet rs = ps.executeQuery();
    ArrayList<Double> value  = new ArrayList<Double>();
    while (rs.next())
    {
        ArrayList<Integer> r=new ArrayList<Integer>();

        r.add(rs.getInt("Budget"));
        r.add(rs.getInt("Day"));

        int vec2[] = r.stream().mapToInt(t -> t).toArray();
        double cos_sim=cosine_similarity(vec1,vec2);
        value.add(cos_sim);
    }

    pick_highest_value_here_and_display(value);
    ps.close();
    rs.close();
    conn.close();


}


这篇关于没有为参数1指定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-17 15:54