Advertisement
Guest User

Untitled

a guest
Jun 8th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3.  
  4. public class test {
  5.     public static void main(String[] args) {
  6.         Connection con = null;
  7.  
  8.         try {
  9. Class.forName("com.mysql.jdbc.Driver");
  10.             con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql", "username", "password");
  11.  
  12.             // Do shit
  13.         } catch(Exception e) {
  14.             e.printStackTrace();   
  15.         } finally {
  16.             if(con != null) {
  17.                 try {
  18.                     con.close();
  19.                 } catch(Exception e) {
  20.                     e.printStackTrace();
  21.                 }
  22.             }
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement