Advertisement
HiranNeri

Conexao

Jun 9th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. public class Conexao {
  2. // JDBC driver name and database URL
  3. static final String DB_DRIVER = "com.mysql.jdbc.Driver";
  4. static final String DB_CONNECTION = "jdbc:mysql://localhost:3306/UBSTech";
  5. static final String DB_USER = "root";
  6. static final String DB_PASSWORD = "";
  7.  
  8. public static Connection getDBConnection() {
  9.  
  10. Connection dbConnection = null;
  11.  
  12. try {
  13.  
  14. Class.forName(DB_DRIVER);
  15.  
  16. } catch (ClassNotFoundException e) {
  17.  
  18. System.out.println(e.getMessage());
  19.  
  20. }
  21.  
  22. try {
  23. dbConnection = DriverManager.getConnection(DB_CONNECTION, DB_USER,DB_PASSWORD);
  24. return dbConnection;
  25.  
  26. } catch (SQLException e) {
  27.  
  28. System.out.println(e.getMessage());
  29.  
  30. }
  31.  
  32. return dbConnection;
  33.  
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement