Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

Java
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();


}
Posted
Updated 21-Aug-15 22:44pm
v2
Comments
Michael_Davies 22-Aug-15 6:33am    
You have a parameter place holder in your sql string and you do not set the value of the parameter.

ps.Parameters.Add(-the value of M_ID to find-)

Better to name the parameter using @paramname instead of ? then

ps.Parameters.AddWithValue("@paramname",-the value of M_ID-)
wseng 23-Aug-15 3:51am    
I should not specific the M_ID

1 solution

Java
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();


}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900