Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. public class DatabaseHelper {
  2.  
  3. public static Connection getConnection() {
  4. String user = ("root");
  5. String password = ("root");
  6. String url = ("jdbc:mysql://localhost:3306/users" +
  7. "?autoReconnect=true&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC");
  8. try {
  9. Class.forName("com.mysql.jdbc.Driver");
  10. } catch (ClassNotFoundException e) {
  11. e.printStackTrace();
  12. }
  13. try {
  14. return DriverManager.getConnection(url, user, password);
  15. } catch (SQLException e) {
  16. e.printStackTrace();
  17. }
  18. return null;
  19. }
  20. public static Properties getConfiguration (){
  21. Properties properties = new Properties();
  22. try {
  23. FileInputStream in = new FileInputStream("my.properties");
  24. properties.load(in);
  25. in.close();
  26. return properties;
  27. } catch (java.io.IOException e) {
  28. e.printStackTrace();
  29. }
  30. return null;
  31. }
  32.  
  33. public static Map getMap() {
  34. Map<String, String> result = new HashMap();
  35. result.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
  36. result.put("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
  37. result.put("hibernate.connection.url", "jdbc:mysql://localhost:3306/test");
  38. result.put("hibernate.connection.username", "root");
  39. result.put("hibernate.connection.password", "root");
  40. result.put("hibernate.show_sql", "true");
  41. result.put("hibernate.hbm2ddl.auto", "create");
  42.  
  43. return result;
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement