How do I perform Database Connection Strings

 

All instances, created in CloudJiffy, are operated as independent containers. To establish the connection to a database from the application, deployed within an application server, I need to set a connection string for it, using either:

 

CNAME of database, e.g. node{node_id}-{environment_name}.{hoster_domain}.

Private IP address.

Public IP address (if attached).

 

1. Database Connection for Java Application:

   

DB types

Connection Code 

MySQL / MariaDB 

String URL = "jdbc:mysql://node{node_id}-{environment_name}.{hoster_domain}/{dbname}";

DriverManager.getConnection(URL, user_name,user_password);

MySQL

Auto-Cluster

String URL = "jdbc:mysql://proxy.{environment_name}.{hoster_domain}:3306/{dbname}";

DriverManager.getConnection(URL, user_name,user_password);

MariaDB

Auto-Cluster

String URL = "jdbc:mariadb://proxy.{environment_name}.{hoster_domain}:3306/{dbname}?usePipelineAuth=false";

DriverManager.getConnection(URL, user_name,user_password);

PostgreSQL

String URL = "jdbc:postgresql://node{node_id}-{environment_name}.{hoster_domain}/{dbname}";

DriverManager.getConnection(URL, user_name,user_password);

MongoDB

Mongo m = new Mongo(node{node_id}-{environment_name}.{hoster_domain});

DB db = m.getDB ({database_name});

if (db.authenticate(user_name,user_password.toCharArray())) {

System.out.println("Connected!");

}

 

For the UTF-8 encoding, modify my connection string according to this:

"jdbc:{dbtype}://{dbtype}{node_id}-{environment_name}.{hoster_domain}/{dbname}?useUnicode=yes&characterEncoding=UTF-8"

 

2. Database Connection for PHP Application:

 

DB types

Connection Code 

MariaDB and MySQL 

mysql_connect('HOST', 'USERNAME', 'PASSWORD')

MongoDB

Mongo("hostaddress", array("username" => "username", "password" => "password"))

PostgreSQL

pg_connect("host=host_address port=5432 dbname=postgres user=webadmin password=password")




Was this article helpful?

mood_bad Dislike 0
mood Like 0
visibility Views: 9113