-1
private void btgetinvActionPerformed(java.awt.event.ActionEvent evt) {
    if(tf_rmid.getText().length()==11){
        JOptionPane.showMessageDialog(null,"REMITTANCE ID IS VALID!");
        try {
                DBUtil util = new DBUtil();
                Connection con = util.getConnection();
                Statement stmt = con.createStatement();
                ResultSet rs = stmt.executeQuery("select bk_det.rm_id from bk_det inner join bk_rep on bk_det.rm_id = bk_rep.rm_id WHERE rm_id = ?");
                String rm = tf_rmid.getText().trim();          
                stmt.setString(1, ""+(rm));
                while(rs.next()){
                   int i = rs.getString("RM ID");
                   String fn = rs.getString("First Name");
                   String ln = rs.getString("Last Name");
                   String title = rs.getString("Title");
                   String city = rs.getString("City");
                   txtFirstName.setText(fn);
                   txtLastName.setText(ln);
                   txtTitle.setText(title);
                   txtCity.setText(city);
                }
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, ex.getMessage());
                Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
            }
    }else{
       JOptionPane.showMessageDialog(null,"PLEASE ENTER VALID REMITTANCE ID!");
    }

}

我正在尝试使用 select 语句从我的数据库中搜索值,但是当我试图获取值时?对于 where 选项我收到错误,我认为这是一个语法错误,任何人都可以帮忙吗???

4

3 回答 3

1

在执行查询之后将参数设置为 Statement 似乎有点奇怪。

int i = rs.getString("RM ID");

这不会编译(如果 rs 是 java.sql.ResultSet 实例)

于 2012-12-30T14:43:17.797 回答
1

使用准备好的语句:

    String query = "select bk_det.rm_id from bk_det inner join bk_rep on bk_det.rm_id = bk_rep.rm_id WHERE rm_id = ?";
    try {
        PreparedStatement preps = con.prepareStatement(query);
        preps.setString(1, ""+(rm));
        preps.execute();
        ...
于 2012-12-30T14:46:57.503 回答
1

以此执行,

select bk_det.rm_id from bk_det inner join bk_rep 
on bk_det.rm_id = bk_rep.rm_id WHERE bk_det.rm_id = ?

可能您在 where 子句中缺少表名

于 2012-12-30T14:39:05.090 回答