0

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

4

2 回答 2

3

您的陈述似乎不一定符合您的想法;

else if(r2.isSelected())//Month-wise   // <-- r2
{
    cmd="SELECT SNO, DATE, COMPANY,STATUS FROM CALLDETAILS WHERE MONTH(DATE)=?";
    parameter=tf1.getText();
}
else if(r2.isSelected())//Username     // <-- r2 again...? Won't ever be hit.

此外,虽然很可能不是你的问题,getInt(1)而且getTimestamp(2)看起来有点危险SELECT *

于 2013-07-30T16:17:22.733 回答
0

检查getConnection()字符串和您的查询/准备语句。

由于它不返回任何结果,因此问题可能出在此处。

于 2013-07-30T16:30:50.003 回答