我正在编写一个程序,当用户使用单选按钮选择某个选项时,会分配参数和 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());
}
没有标记为 HERE 的语句的输出。这是为什么?