daily pastebin goal
59%
SHARE
TWEET

Untitled

a guest May 30th, 2017 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.sql.*;
  2.  
  3. public class Login {
  4.  
  5.     static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
  6.     static final String DB_URL = "jdbc:mysql://127.0.0.1:3306/Account";
  7.  
  8.     static final String USERNAME = "root";
  9.     static final String PASSWORD = "password";
  10.  
  11.     public static void main(String[] args) {
  12.         Connection conn = null;
  13.         Statement stmt = null;
  14.         try{
  15.             Class.forName(JDBC_DRIVER);
  16.             conn = DriverManager.getConnection(DB_URL,USERNAME,PASSWORD);
  17.             System.out.println("\n- MySQL Connection");
  18.             stmt = conn.createStatement();
  19.  
  20.             String sql;
  21.             sql = "SELECT number,id, pw FROM account";
  22.             ResultSet rs = stmt.executeQuery(sql);
  23.  
  24.             while(rs.next()){
  25.                 int num = rs.getInt("number");
  26.                 String ID = rs.getString("ID");
  27.                 String PW = rs.getString("PW");
  28.  
  29.                 System.out.println(num + " => ID : " + ID + "   PW : " + PW);
  30.  
  31.             }
  32.             rs.close();
  33.             stmt.close();
  34.             conn.close();
  35.         }catch(SQLException se1){
  36.             se1.printStackTrace();
  37.         }catch(Exception ex){
  38.             ex.printStackTrace();
  39.         }finally{
  40.             try{
  41.                 if(stmt!=null)
  42.                     stmt.close();
  43.             }catch(SQLException se2){
  44.             }
  45.             try{
  46.                 if(conn!=null)
  47.                     conn.close();
  48.             }catch(SQLException se){
  49.                 se.printStackTrace();
  50.             }
  51.         }
  52.         System.out.println("\n\n- MySQL Connection Close");
  53.     }
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top