This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Displaying database Field value on a TextField Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Displaying database Field value on a TextField" Watch "Displaying database Field value on a TextField" New topic
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying database Field value on a TextField
 
Similar Threads
Data Consistency
Field Refresh Using AJAX in Struts2
Need help in generating a second vector list from the frist vector which...
Bug in code
jsp page submit datas back to itself