Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DBconnector {
- private String host = System.getenv("OPENSHIFT_MYSQL_DB_HOST");
- private String port = System.getenv("OPENSHIFT_MYSQL_DB_PORT");
- private String username = System.getenv("OPENSHIFT_MYSQL_DB_USERNAME");
- private String password = System.getenv("OPENSHIFT_MYSQL_DB_PASSWORD");
- private String url = String.format("jdbc:mysql://%s:%s",host,port);
- private Connection connection;
- private static DBconnector dBconnector;
- private DBconnector() {
- Properties properties = new Properties();
- properties.setProperty("useUnicode", "true");
- properties.setProperty("characterEncoding", "utf8");
- properties.setProperty("user", username);
- properties.setProperty("password", password);
- try {
- Class.forName("com.mysql.jdbc.Driver");
- this.connection = DriverManager.getConnection(url , properties);
- } catch (SQLException | ClassNotFoundException d) {
- d.printStackTrace();
- }
- }
- public static DBconnector getInstance() {
- if (dBconnector == null)
- dBconnector = new DBconnector();
- return dBconnector;
- }
- public Connection getConnection() {
- return connection;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement