| Author |
Displaying database Field value on a TextField
|
Patrick Mugabe
Ranch Hand
Joined: Jan 08, 2002
Posts: 132
|
|
I am trying to run a query which selects data from a single field, i.e StudentID from the student table. The StudentID should then go into the TextField of my frame as set Text, i.e txtStudentID.setText(Value from database). HOW CAN I DO THIS? Please HELP if posiible with the aid of a simple example!!!
|
 |
Bhupendra Malviya
Greenhorn
Joined: Oct 01, 2003
Posts: 15
|
|
Hi friend, You can use following lines of code String query="Select Studentid from Students where Name='Bhupendra'"; ResultSet rs=stmt.executeQuery(query); if(rs.next()) StudentId.setText(rs.getObject(1).toString()); else StudentId.setText("Named Student not found in database "); Hope it sorts out your problem
|
 |
Sainudheen Mydeen
Ranch Hand
Joined: Aug 18, 2003
Posts: 218
|
|
Originally posted by Bhupendra Malviya: Hi friend, You can use following lines of code String query="Select Studentid from Students where Name='Bhupendra'"; ResultSet rs=stmt.executeQuery(query); if(rs.next()) StudentId.setText(rs.getObject(1).toString()); else StudentId.setText("Named Student not found in database "); Hope it sorts out your problem
StudentId.setText(rs.getString(1)); will also work. -Sainudheen
|
 |
 |
|
|
subject: Displaying database Field value on a TextField
|
|
|