Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. public class DBConn {
  2.    
  3.     Statement stmt = null;
  4.     ResultSet rs = null;
  5.     Connection con = null;
  6.     static{
  7.        
  8.         try {  
  9.             // TREIBER LADEN
  10.             Class.forName("com.mysql.jdbc.Driver");
  11.         } catch (ClassNotFoundException e) {
  12.             // TODO Auto-generated catch block
  13.             e.printStackTrace();
  14.         }
  15.        
  16.     }
  17.    
  18.  
  19.     public static Connection openConnection(){
  20.         // WOHIN WIR WOLLEN
  21.         String connectionUrl = "jdbc:mysql://URL/;databaseName=NDDMA;";
  22.        
  23.         String url ="jdbc:mysql://URL:PORT";
  24.  
  25.         Connection con = null;
  26.         try {
  27.             con = DriverManager.getConnection(url,"USER", "PW");
  28.         } catch (SQLException e) {
  29.             // TODO Auto-generated catch block
  30.             e.printStackTrace();
  31.         }
  32.        
  33.         return con;
  34.        
  35.     }
  36.    
  37.     public void closeConnection(Connection con,Statement stmt,ResultSet rs){
  38.        
  39.        
  40.        
  41.         try {
  42.             rs.close();
  43.             stmt.close();
  44.             con.close();
  45.            
  46.         } catch (SQLException e) {
  47.             // TODO Auto-generated catch block
  48.             e.printStackTrace();
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement