Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. package domyslny;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.PreparedStatement;
  5.  
  6. public class Main {
  7.  
  8.     public static void main(String[] args) throws Exception {
  9.         // TODO Auto-generated method stub
  10.         createTable();
  11.     }
  12.  
  13.    
  14.    
  15.     public static void createTable() throws Exception{
  16.         try {
  17.             Connection con = getConnection();
  18.             PreparedStatement create = con.prepareStatement("CREATE TABLE IF NOT EXIST aaaa(id int NO NULL AUTO_INCREMENT, first varchar(255), last varchar(255), PRIMARY KEY (id))");
  19.             create.executeUpdate();
  20.         }catch(Exception e) {System.out.println(e);}
  21.         finally {System.out.println("Function complete.");}
  22.     }
  23.    
  24.     public static Connection getConnection() throws Exception{
  25.        
  26.         try {
  27.             String driver = "com.mysql.jdbc.wypozyczalnia";
  28.             String url = "jdbc:mysql://localhost:1521/wypozyczalnia";
  29.             String username="LUKASBURZA";
  30.             String password = "abcd";
  31.             Class.forName(driver);
  32.            
  33.             Connection conn = DriverManager.getConnection(url, username, password);
  34.             System.out.println("Connected");
  35.             return conn;
  36.             }catch(Exception e) {System.out.println(e);}
  37.        
  38.         return null;
  39.     }
  40.    
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement