Advertisement
Guest User

Untitled

a guest
Jun 10th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 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", "mircea");
  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. // TODO Auto-generated catch block
  22. e.printStackTrace();
  23. }
  24. return null;
  25. }
  26.  
  27. public static void closeConnection(Connection con) {
  28. try {
  29. con.close();
  30. } catch (SQLException e) {
  31. // TODO Auto-generated catch block
  32. e.printStackTrace();
  33. }
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement