Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Connection conn = DriverManager.getConnection(
- "jdbc:mysql:myhostname1",
- "myLogin",
- "myPassword" );
- Statement stmt = conn.createStatement();
- try {
- ResultSet rs = stmt.executeQuery( "SELECT * FROM MyTable" );
- try {
- while ( rs.next() ) {
- int numColumns = rs.getMetaData().getColumnCount();
- for ( int i = 1 ; i <= numColumns ; i++ ) {
- // Column numbers start at 1.
- // Also there are many methods on the result set to return
- // the column as a particular type. Refer to the Sun documentation
- // for the list of valid conversions.
- System.out.println( "COLUMN " + i + " = " + rs.getObject(i) );
- }
- }
- } finally {
- try { rs.close(); } catch (Throwable ignore) { /* Propagate the original exception
- instead of this one that you may want just logged */ }
- }
- } finally {
- try { stmt.close(); } catch (Throwable ignore) { /* Propagate the original exception
- instead of this one that you may want just logged */ }
- }
- Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
- ResultSet rs = stmt.executeQuery("SELECT * FROM MyTable");
- StringBuffer sb=new StringBuffer();//create string buffer to hold results
- //use html to enable newlines in jlabel
- sb.append("<html>");
- while (rs.next()) {
- sb.append(rs.getString("a")).append("<br>");//append results to buffer
- }
- sb.append("</html>");
- //create label with results
- JLabel label=new JLabel(sb.toString());
- JLabel label=new JLabel();
- //read results to buffer
- label.setText(sb.toString());
Add Comment
Please, Sign In to add comment