hello friends, can anyone help me?? I am facing this problem for past one week. I could't set the values from database. here is the code:
private JTextField getJTextField1() {
if(text == null) {
text = new JTextField();
}
return text;
}
private AbstractAction getSearch() {
if(search == null) {
search = new AbstractAction("SEARCH", null) {
/**
*
*/
private static final long serialVersionUID = 1L;
public void actionPerformed(ActionEvent evt) {
try{
ResultSet rs;
String st1=text.getText();
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://192.168.36.1:3306/atmconsol","project","password");
PreparedStatement pst=con.prepareStatement("select * from form1 where TerminalID=?");
System.out.println(st1);
pst.setString(1, st1);
JOptionPane.showMessageDialog(null,"Prepared Stmt after setting the values " + pst.toString());
rs = pst.executeQuery();
gui.display1 ts= new gui.display1();
ts.dis(st1);
System.out.println(ts);
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null,"TRY AGAIN!!!Cannot find such ID!");
text .setText("");
text.requestFocus(true);
System.out.println("error while validating"+e);
e.printStackTrace();
System.out.println(e);
}
}
};
}
return search;
}
}
//**display1.java**//
void dis(String st1)
{
try
{
String st=td.getText();
String st2=make.getText();
String st3=proto.getText();
String emv=text.getText();
String st5=bnqry.getText();
String st6=fc.getText();
String st7=ft.getText();
String st8=pc.getText();
String st9=ms.getText();
String st10=cb.getText();
String st11=wd.getText();
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connt = DriverManager.getConnection("jdbc:mysql://192.168.36.1:3306/atmconsol","project","password");
PreparedStatement pstmt = connt.prepareStatement("select TerminalId,make,protocol,EMVsupport,BalanceEnquiry,Fastcash,fundtransfer,chequebook,pinchange,ministatement,withdrawal from form1 where TerminalId=?;");
pstmt.setString(1, st1);
ResultSet rs = pstmt.executeQuery();
while(rs.next())
{
System.out.println("******* : "+rs.getString("TerminalId"));
td.setText(rs.getString(st));
make.setText(rs.getString(st2));
proto.setText(rs.getString(st3));
text.setText(rs.getString(emv));
bnqry.setText(rs.getString(st5));
fc.setText(rs.getString(st6));
ft.setText(rs.getString(st7));
pc.setText(rs.getString(st8));
ms.setText(rs.getString(st9));
cb.setText(rs.getString(st10));
wd.setText(rs.getString(st11));
}
JOptionPane.showMessageDialog(null,"Prepared Stmt after setting the values " + pstmt.toString());
}catch(Exception ex)
{
JOptionPane.showMessageDialog(null,"Error!");
System.out.println("error while validating"+ex);
ex.printStackTrace();
}
}
can anyone help me out of this issue plzzz!!!! Thanks in advance!!!!
hi friend,
You are trying to set the value of Terminalid in the SQL query to String put the ? between single quote ('). Probably error is generating from this statement.
Thanks.