我正在寫使用單選按鈕,其中,當用戶選擇一個特定的選擇程序,然後參數和SQL語句會被分配:查詢不返回輸出
if(r1.isSelected())//SNo
{
cmd="SELECT * FROM CALLDETAILS WHERE SNo=?";
parameter=tf1.getText();
}
else if(r2.isSelected())//Month-wise
{
cmd="SELECT SNO, DATE, COMPANY,STATUS FROM CALLDETAILS WHERE MONTH(DATE)=?";
parameter=tf1.getText();
}
else if(r2.isSelected())//Username
{
cmd="SELECT * FROM CALLDETAILS WHERE ATTENDED_BY=?";
parameter=tf1.getText();
}
else if(r3.isSelected())//Company
{
cmd="SELECT * FROM CALLDETAILS WHERE COMPANY=?";
parameter=tf1.getText();
}
else//Status
{
cmd="SELECT * FROM CALLDETAILS WHERE Status=?";//Resolved. in process, pending
parameter=tf1.getText();
}
當我運行此:
try
{
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/tenderdetails?user=root&password=");
PreparedStatement ps;
ps=con.prepareCall(cmd);
ps.setString(1,parameter);
ResultSet rs=ps.executeQuery();
while(rs.next())
{
int sno=rs.getInt(1);
Timestamp dt=rs.getTimestamp(2);
System.out.println(sno+ " "+dt);//HERE!
}
con.close();
System.out.println("here too");
}
catch(SQLException se)
{
JOptionPane.showMessageDialog(this, "Error: "+se.getMessage());
}
沒有標明這裏的語句的輸出。這是爲什麼?
因爲你的SQL語句不返回任何命中...... – home
看來你的查詢沒有返回任何東西(while循環不執行的話)。 – kosa
您是否遇到拋出的異常? –