Guest User

Untitled

a guest
Jan 3rd, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. package examplediploma.dbutils;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class DbConnectionUtils {
  8.  
  9. private static final String JDBC_MYSQL_HOST = "jdbc:mysql://localhost:3306/";
  10. private static final String MYSQL_JDBC_DRIVER_NAME = "com.mysql.jdbc.Driver";
  11. private static final String DB_NAME = "sourceit";
  12. private static final String USERNAME = "root";
  13. private static final String PASSWORD = "root";
  14.  
  15. public static Connection getConnection() {
  16. try {
  17. Class.forName(MYSQL_JDBC_DRIVER_NAME);
  18. return DriverManager.getConnection(JDBC_MYSQL_HOST
  19. + DB_NAME,
  20. USERNAME,
  21. PASSWORD);
  22. } catch (ClassNotFoundException | SQLException e) {
  23. throw new RuntimeException(e);
  24. }
  25. }
  26.  
  27. }
Add Comment
Please, Sign In to add comment