Advertisement
Guest User

Untitled

a guest
Jun 10th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. package ro.scoalainformala.bankjdbc.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 getConnection() {
  11.         Properties connectionProperties = new Properties();
  12.         connectionProperties.put("user", "root");
  13.         connectionProperties.put("password", "random112");
  14.  
  15.         String connString = "jdbc:mysql://localhost:3306/bank_curs";
  16.         try {
  17.             Connection con = DriverManager.getConnection(connString, connectionProperties);
  18.             System.out.println("Conexiunea la baza de date a fost deschisa");
  19.             return con;
  20.         } catch (SQLException e) {
  21.             e.printStackTrace();
  22.         }
  23.         return null;
  24.     }
  25.  
  26.     public static void closeConnection(Connection con) {
  27.         try {
  28.             con.close();
  29.         } catch (SQLException e) {
  30.             e.printStackTrace();
  31.         }
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement