我有一個代碼,它將從公司表中讀取行並插入到JComboBox中。運行java代碼時無法從mysql數據庫檢索行
當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);
}
幫我出這一點。 在此先感謝。
'comboCompanyName.addItem(rs.getString(「comp_name」));'comboCompanyName'後面的任何其他代碼? –
您的空檢查是在您訪問該變量之後,因此您不會記錄任何內容。 – unholysampler
信息'找不到數據'來自哪裏?我無法在您的代碼中找到它。 – jlordo