0

当我选择一个特定的组合框项目时,我想在数据库中输入空值,以便我可以获得该列的行数,留下空行

String bnn = (txtboxno.getText().trim() == null || 
              txtboxno.getText().equals("")) ? "null" : txtboxno.getText();
Object nsn = (cbnotstat.getSelectedItem() == null || cbnotstat.getSelectedItem().equals("")) ? "0" : cbnotstat.getSelectedItem();

PreparedStatement stmt = con.prepareStatement("select COUNT(box_no)as total from soil_det WHERE rm_id = ?");
ResultSet rs;
String rm = tf_rm_id.getText();
stmt.setLong(1, Long.parseLong(rm));
rs = stmt.executeQuery();

while (rs.next()) {
    tf_boxno.setText(rs.getString("total"));
}

我在上面尝试过,但它显示输入字符串“null”错误。

4

1 回答 1

0

同样,您需要检查 rm_id

String rm = tf_rm_id.getText();
rm = rm == null || rm.isEmpty() ? 0 : rm ; // consider 0 is valid here
long value ;
try {
  value = Long.parseLong(rm) ;
  stmt.setLong(1, value);
} catch(NumberFormatException  ee) {
  System.out.println("Praser exception, invalid input");
}
于 2013-01-13T09:06:03.963 回答