当我选择一个特定的组合框项目时,我想在数据库中输入空值,这样我就可以获得该列的rowcount而留下空行
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"));
}
我上面已经尝试过,但它显示的是inputtring“null”错误。
答案 0 :(得分: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");
}