Connecting to database in Jelastic
All instances in Jelastic are independent containers, so if you want to establish connection to database from application (which is deployed to Application Server) you need to set connection string by the following parameters:
  • CNAME of database, eg. {mysql}-{environment_name}.{hoster_domain}
  • Private IP address
  • Public IP address, in case you purchased it

Note: you cannot establish connection from application to database specifying localhost as a connection string.


When you create a new environment which includes a database server (MySQL, MariaDB, PostgreSQL, MongoDB, CouchDB), Jelastic sends you an email with ROOT login and password to the database Administrative console.

To get to the database administrative console:
  • Type the following URL in your browser:
    {dbtype}-{environment-name}.{hoster_domain}
  • Databasestring in URL - {dbtype}
    MySQLmysql
    MariaDBmariadb
    PostgreSQLpostgres
    MongoDBmongodb
    CouchDBcouchdb
  • Or, in Jelastic dashboard (app.{hoster_domain}), expand the environment and click Open in Browser button next to the database.

    Use the credentials you received on email to log in to the database administrative panel, then create the databases and user accounts that your application needs.

    In your Java application you would likely have the database connection code similar to the one below:
  • MySQL
  • String URL = "jdbc:mysql://mysql-{your-environment-name}.{hoster_domain}/{dbname}";
    DriverManager.getConnection(URL, user_name,user_password);
    
  • MariaDb
  • String URL =  "jdbc:mysql://mariadb-{your-environment-name}.{hoster_domain}/{dbname}";
    DriverManager.getConnection(URL, user_name,user_password);
  • PostgreSQL
  • String URL = "jdbc:postgresql://postgres-{your-environment-name}.{hoster_domain}/{dbname}";
    DriverManager.getConnection(URL, user_name,user_password);
  • MongoDB
  • Mongo m = new Mongo(mongodb-{your-environment-name}.{hoster_domain});        
    DB db = m.getDB({data-base-name});
          if (db.authenticate(user_name,user_password.toCharArray())) {
                    System.out.println("Connected!");                
          }
  • CouchDB
  • String host = "couchdb-{your-environment-name}.{hoster_domain}";
    int port = 80;
    String username = "username";
    String password = "password";
    
    Session dbSession = new Session(host, port, username, password);


    For UTF-8 encoding, modify your connection string to this:
     
    "jdbc:{dbtype}://{dbtype}-{your-environment-name}.{hoster_domain}/{dbname}?useUnicode=yes&characterEncoding=UTF-8"

The information on your hoster domain you can find in the document Hosters Info (last column in the first table).
 
What's next?
 
 

Account registration failed

We suspect that this is due to network issues - so please try again in a minute. If your second attempt fails please email us at info@jelastic.com and we will get you in.

Vote for features