Reputation: 3
I'm writing a program where when user selects a certain choice using radio buttons, then parameters and sql statements get assigned:
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();
}
When I run this:
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());
}
There is no output of the statement marked HERE. Why is that?
Upvotes: 0
Views: 94
Reputation: 1104
check the getConnection()
string and your Query/Prepared statement.
Since it doesn't return any results the problem is likely here.
Upvotes: 0
Reputation: 180917
It would seem that your statements aren't necessarily set to what you think;
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.
Also, although most likely not your problem, getInt(1)
and getTimestamp(2)
seem a bit dangerous with SELECT *
.
Upvotes: 3