【问题标题】:insert null values into database when a particular combobox item is selected选择特定组合框项时将空值插入数据库
【发布时间】:2013-01-13 08:52:56
【问题描述】:

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

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”错误。

【问题讨论】:

  • 你能发布确切的错误字符串吗?

标签: java sql jdbc


【解决方案1】:

同样你需要检查 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");
}

【讨论】:

    猜你喜欢
    • 2016-11-16
    • 2013-12-25
    • 1970-01-01
    • 1970-01-01
    • 2014-08-27
    • 1970-01-01
    • 1970-01-01
    • 2013-03-27
    • 2010-09-19
    相关资源
    最近更新 更多