problem in setting the values from database
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!!!!
View Answers
May 18, 2013 at 5:16 PM
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.
Ads
Related Tutorials/Questions & Answers:
problem in setting the values from database
problem in
setting the
values from database hello friends,
can... the
values from database.
here is the code:
private JTextField getJTextField1... Stmt after
setting the
values " + pst.toString());
rs
get values from Excel to database
get
values from Excel to database hi i want to insert
values from Excel file into database.Whatever field and contents are there in excel file that should go to
database which exists. am using SQL Server management studio
Advertisements
Problem in accessing data from Database
Problem in accessing data
from Database hi.....
i'm making a project on servlet and jsp with ms access 2007 at the backend. One field in my
database... someone plz help me out with this
problem
insert values from excel file into database
the following link:
Insert
values from excel file to
database...insert
values from excel file into database hi i want to insert
values from Excel file into database.Whatever field and contents are there in excel
Retrieve values from database using views
Retrieve
values from database using views hi.........
I have a huge
database so i have created views in
database where i am selecting only...
from that created views and display on form . I am trying to do so but its
fetch values from database into text field
fetch
values from database into text field please provide the example for fetching
values from database into text field of table
as if i am trying following
String query = "select *
from LTCINFO.PERSONS";
st1
fetch values from database into text field
fetch
values from database into text field please provide the example for fetching
values from database into text field of table
wth edit... *
from LTCINFO.PERSONS";
st1 = con.createStatement();
rs = st1.executeQuery(query
How to update,Delete database values from jtable cells ..
How to update,Delete
database values from jtable cells .. Hello Sir, I am working on a project in which i have to fetch the
values from database... records
from the table cells by entering new
values there only ...
Sir,plz send me
how to display values from database into table using jsp
how to display
values from database into table using jsp I want to display
values from database into table based on condition in query, how... the
values from database based on the bookname or authorname entered must be display
How to update,Delete database values from jtable cells ..
How to update,Delete
database values from jtable cells .. hello Sir...
from database into jtable of a jpanel.. Now Sir, According to my need i have to update the cell
values from there only means that whatever
values i ma entering
problem in database
problem in
database thanks for web site.
I want change this code to insert data into PostgreSql
database using jsp,servlets.
but i getting... into sample
VALUES(?,?)");
pst.setString(1,username);
pst.setString(2,pass
database problem
database problem I did connect my jsp page to
database and it showed the result on another jsp page but i want to show the data of that field on which i click to mouse
from the jsp page where all the data field has been showed
database problem
database problem I did connect my jsp page to
database and it showed the result on another jsp page but i want to show the data of that field on which i click to mouse
from the jsp page where all the data field has been showed
Oracle 9i database problem
Oracle 9i
database problem Hi Somebody has given the solution but i.............,send reply immediately. I have a
problem in Oracle9i .I have installed... and columns data ,then i gave command select *
from ....; .Then i got the table