Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. package ro.scoalainformala.jdbc.helper;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import java.util.Properties;
  7.  
  8. public class DBHelper {
  9.  
  10.     public static Connection openConnection() {
  11.         try {
  12.             Class.forName("com.mysql.jdbc.Driver");
  13.         } catch (ClassNotFoundException e1) {
  14.             e1.printStackTrace();
  15.         }
  16.         Properties connectionProps = new Properties();
  17.         connectionProps.put("user", "root");
  18.         connectionProps.put("password", "1qa2ws3ed");
  19.         try {
  20.             Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bank_curs", connectionProps);
  21.             return conn;
  22.         } catch (SQLException e) {
  23.             e.printStackTrace();
  24.         }
  25.         return null;
  26.     }
  27.    
  28.     public static void closeConnection(Connection conn) {
  29.         try {
  30.             conn.close();
  31.         } catch (SQLException e) {
  32.             e.printStackTrace();
  33.         }
  34.     }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement