Advertisement
joseleonweb

Untitled

May 12th, 2021
753
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. package org.mysqltutorial;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7.  
  8. public class Main {
  9.    
  10.     public static void main(String[] args) {
  11.         //
  12.         String sql = "SELECT first_name, last_name, email " +
  13.                      "FROM candidates";
  14.        
  15.         try (Connection conn = MySQLJDBCUtil.getConnection();
  16.              Statement stmt  = conn.createStatement();
  17.              ResultSet rs    = stmt.executeQuery(sql)) {
  18.            
  19.             // loop through the result set
  20.             while (rs.next()) {
  21.                 System.out.println(rs.getString("first_name") + "\t" +
  22.                                    rs.getString("last_name")  + "\t" +
  23.                                    rs.getString("email"));
  24.                    
  25.             }
  26.         } catch (SQLException ex) {
  27.             System.out.println(ex.getMessage());
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement