Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Posting Query Results to a JTextArea

Status
Not open for further replies.

MikeMoore

Vendor
May 27, 2003
3
0
0
US
Does anyone know where I can get example code on how to post jdbc query results into a JTextArea? Any help would be great.
 
you can use the append method. sorry no example.
 
Here is an example snippet. This uses an Oracle database. The ResultSet.next() method iterates through the records returned.

JTextArea textArea1 = new JTextArea(10, 50);
String query = "select emp_name, emp_id from employee order by emp_name";
Connection con = null;
Statement stmnt = null;
ResultSet rs = null;
try {
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
con = DriverManager.getConnection("jdbc:eek:racle:thin:mad:oraclehost:1521:sid", "username", "password");
stmnt = con.createStatement();
rs = stmnt.executeQuery(query);
while(rs.next()){
textArea1.append(rs.getString("emp_name"));
textArea1.append(" ");
textArea1.append(rs.getString("emp_id"));
textArea1.append(System.line.separator);
}
if(stmnt != null){
stmnt.close();
}
if(con != null){
con.close();
}
}
catch(SQLException e){
System.out.println("Error with database retrieval");
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top