I was able to configure the MySQL database on OpenShift using phpMyAdmin and all. I was told the host name and port my for my database: $ OPENSHIFT_MYSQL_DB_HOST and $ OPENSHIFT_MYSQL_DB_PORT respectively, which I put in my context.xml file as follows:
<context-param> <param-name>driver</param-name> <param-value>com.mysql.jdbc.Driver</param-value> </context-param> <context-param> <param-name>url</param-name> <param-value>jdbc:mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/burgerjoint</param-value> </context-param> <context-param> <param-name>user</param-name> <param-value>admin******</param-value> </context-param> <context-param> <param-name>password</param-name> <param-value>*********</param-value> </context-param>
Code for setting up the connection:
public void contextInitialized(ServletContextEvent event) {
but the problem is that the connection is null on the server, and I don't understand why. Did I do something wrong? The code works when I try it on localhost. And as far as I can tell, I have all the necessary libraries:

Thanks for the help:)
Update
I changed the connection code as follows:
{ if (connection != null) return connection; try { Properties dbProperties = new Properties(); InputStream input = DatabaseUtil.class.getClassLoader().getResourceAsStream(DB_PROPERTIES_FILE); dbProperties.load(input); String url = ""; if (appIsDeployed) { String host = System.getenv("$OPENSHIFT_MYSQL_DB_HOST"); String port = System.getenv("$OPENSHIFT_MYSQL_DB_PORT"); String name = "burgerjoint"; url = "jdbc:mysql://" + host + ":" + port + "/" + name; } else { url = dbProperties.getProperty(PARAM_URL); } String driver = dbProperties.getProperty(PARAM_DRIVER); String username = dbProperties.getProperty(PARAM_USERNAME); String password = dbProperties.getProperty(PARAM_PASSWORD); Class.forName(driver); connection = DriverManager.getConnection(url, username, password);
but it still gives a null connection. The values ββof System.getenv("$OPENSHIFT_MYSQL_DB_HOST") and System.getenv("$OPENSHIFT_MYSQL_DB_PORT") are zero.
source share