+ 4
Can anyone help me to retrive data from database
I have connect data base properly to java netbeans.I need to get row by row data to the jave and disply it it using system.out.println.can anyone help
2 Answers
+ 26
try {
Class.forName .... ;
Connection Con=Driver Manager ... ;
Syring id,s;
id=tf1.getText ();
s="select * from <table name> where <field name>=id;"
Statement st=Con.createStatement();
ResultSet rs=st.executeQuery (s);
if (!rs.next ())
JOptionPane.showMessageDialog (null,"no such record");
else {
tf2.setText (rs.getString ("<field name in table>");
. //fields to retrieve đ
.
. }
}
catch (Exception e){
JOptionPane.showMessageDialog(null,e.getMessage ());}
//hope it helpsâș
+ 2
yeah thank you