Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can not be get and set values from the database

 
Hewa Naimanage Sumedha Amalka
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys, I need to assign the value which got from database and show it as a text field of may frame created,
But the thing is both of valuse are different (Strings and Textfield)
So, can not be assigned

Help me out,


try {
// Create a result set containing all data from my_table
Statement stmt = conn1.createStatement();
ResultSet rs = stmt.executeQuery("SELECT IndexNo, RecidentTP, MobileTP FROM addbook");


// The inserting valu getting to a String
String inpindx = inindx.getText();

// Get the data from the row using the column index
String tblindx = rs.getString("IndexNo");


if (inpindx.equals(tblindx)) {

NewFrame1 fr = new NewFrame1();

String srec1 = rs.getString("RecidentTP");
String smob1 = rs.getString("MobileTp");


//assigning to frame field to tables values

// fr.sre1 = srec1.;
// fr.smob = smob1;

fr.setVisible(true);
}

else {
JOptionPane.showMessageDialog(null,"Incorrect IndexNo");

}
}
catch (Exception e) {
}
inindx.setText(null);
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sumedha,

You are invoking resultset without calling its next() method, I am not sure if its causing an exception or not....but certainly It will not return any result.

Do something like this


OR




Shailesh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic