Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying database Field value on a TextField

 
Patrick Mugabe
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic