Guest User

Untitled

a guest
Jan 17th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. Connection conn = DriverManager.getConnection(
  2. "jdbc:mysql:myhostname1",
  3. "myLogin",
  4. "myPassword" );
  5. Statement stmt = conn.createStatement();
  6. try {
  7. ResultSet rs = stmt.executeQuery( "SELECT * FROM MyTable" );
  8. try {
  9. while ( rs.next() ) {
  10. int numColumns = rs.getMetaData().getColumnCount();
  11. for ( int i = 1 ; i <= numColumns ; i++ ) {
  12. // Column numbers start at 1.
  13. // Also there are many methods on the result set to return
  14. // the column as a particular type. Refer to the Sun documentation
  15. // for the list of valid conversions.
  16. System.out.println( "COLUMN " + i + " = " + rs.getObject(i) );
  17. }
  18. }
  19. } finally {
  20. try { rs.close(); } catch (Throwable ignore) { /* Propagate the original exception
  21. instead of this one that you may want just logged */ }
  22. }
  23. } finally {
  24. try { stmt.close(); } catch (Throwable ignore) { /* Propagate the original exception
  25. instead of this one that you may want just logged */ }
  26. }
  27.  
  28. Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
  29. ResultSet rs = stmt.executeQuery("SELECT * FROM MyTable");
  30.  
  31. StringBuffer sb=new StringBuffer();//create string buffer to hold results
  32.  
  33. //use html to enable newlines in jlabel
  34. sb.append("<html>");
  35.  
  36. while (rs.next()) {
  37. sb.append(rs.getString("a")).append("<br>");//append results to buffer
  38. }
  39. sb.append("</html>");
  40.  
  41. //create label with results
  42. JLabel label=new JLabel(sb.toString());
  43.  
  44. JLabel label=new JLabel();
  45.  
  46. //read results to buffer
  47.  
  48. label.setText(sb.toString());
Add Comment
Please, Sign In to add comment