Advertisement
Guest User

Untitled

a guest
Nov 29th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. public static Connection getConnection(String key, boolean useConnectionPool, String poolName) {
  2. Connection connection = null;
  3. String alias = "DBCP" + poolName + "_" + key;
  4. String driverClass = "com.mysql.jdbc.Driver";
  5. checkAndLoadProps();
  6. String driverUrl = "jdbc:mysql://" + props.getProperty(key + "_DBMS_URL") + "/" + props.getProperty(key + "_DEF_SCHEMA") + "?autoReconnect=true&useUnicode=true&characterEncoding=utf8&jdbcCompliantTruncation=false&rewriteBatchedStatement=true";
  7. String connectionPoolUrl = "proxool." + alias + ":" + driverClass + ":" + driverUrl;
  8. try {
  9. if (useConnectionPool) {
  10. info.remove("user");
  11. String user = props.getProperty(key + "_CLIENT");
  12. info.setProperty("user", user);
  13. info.remove("password");
  14. String password = props.getProperty(key + "_CLIENT_PASS");
  15. info.setProperty("password", password);
  16. String host = props.getProperty(key + "_DBMS_URL");
  17.  
  18. synchronized (poolName) {
  19. connection = DriverManager.getConnection(connectionPoolUrl, info);
  20. }
  21.  
  22. }
  23. if (connection != null) {
  24. return connection;
  25. } else {
  26. System.out.println("DB Connection Not Established");
  27. }
  28.  
  29. } catch (Exception ex) {
  30. System.out.println("DB Connection Not Established::" + ex.getMessage());
  31. ex.printStackTrace();
  32. }
  33. return null;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement