我有一个代码,它将从公司表中获取行并插入到 JComboBox 中。
当 APP 在调试模式下运行时,结果集会填充数据。但是在正常执行时,结果集是空的!
我正在使用Netbeans IDE 7.0.1
开发和 phpmyadmin mysql 数据库版本5.1.37
。
下面是我的代码:
boolean isvalue = false; // variable to identify if the company name found or not.
ResultSet rs = null;
try {
st = con.createStatement();
if(con == null) {
logger.error("Database Connection Not available.");
throw new NullPointerException();
}
//Set the company name to combo box
rs = st.executeQuery("Select comp_name from company");
while (rs.next()) {
comboCompanyName.addItem(rs.getString("comp_name"));
isvalue = true; //Set true if found
}
} catch (SQLException ex) {
System.out.println("SQLError found while updating information." + ex.getMessage());
} catch (Exception ex) {
System.out.println("Error found while updating information." + ex.getMessage());
}
if (!isvalue) //Check company information available
{
JOptionPane.showMessageDialog(null, "System could not found any company information.", "Error", JOptionPane.WARNING_MESSAGE);
}
帮我解决这个问题。提前致谢。