Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.2.1 |  CUBRID 8.3.0 |  CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 | 

Connection Configuration

The DriverManager is a basic service for JDBC driver management and performs functions such as selecting a database driver and creating a new database connection. If the CUBRID JDBC driver is registered, database connection is made by calling the DriverManager.getConnection (db-url, user-id, password) function. The getConnection function returns the Connection object, which is used for query and command executions and transaction commit or rollback. The parameter db-url, which is for connection configuration, is as follows:

jdbc:cubrid:<host>:<port>:<db-name>:[user-id]:[password]:[?<property> [& <property>]]

 

<host> ::=

hostname | ip_address

 

<property> ::=

althosts= <alternative_hosts> | rctime= <second> | charset= <character_set>

 

<alternative_hosts> :

<standby_broker1_host>:<port> [,<standby_broker2_host>:<port>]

  • <host> : IP address or host name where the CUBRID Broker is running
  • <port> : Broker port number (default : 33000)
  • <db-name> : The name of the database to connect
  • [user-id] : The user that will be connected to the database. There are two users in the database by default: DBA and PUBLIC. If you enter an empty string (" "), you will connect to the database as a PUBLIC user.
  • [password] : If there is no password set for the user, enter an empty string (" ").
  • althosts : One or more host IP of standby broker and connection port to be failed over in HA environment
  • rctime : Interval time (in seconds) to fail over an active server during system failure. For more information, see the example in the HA-Related JDBC Configuration.
  • charset : Character set (charset) of database to be connected
Example 1

--connection URL string when user name and password omitted

 

URL=jdbc:CUBRID:127.0.0.1:31000:db1:::

 

--connection URL string when charset property specified

 

URL=jdbc:CUBRID:127.0.0.1:31000:db1:::?charset=utf-8

 

--connection URL string when a property(althosts) specified for HA

URL=jdbc:CUBRID:127.0.0.1:31000:db1:::?althosts=127.0.0.2:31000,127.0.0.3:31000

 

--connection URL string when properties(althosts,rctime) specified for HA

URL=jdbc:CUBRID:127.0.0.1:31000:db1:::?althosts=127.0.0.2:31000,127.0.0.3:31000&rctime=600

 

--connection URL string when properties(althosts,rctime, charset) specified for HA

URL=jdbc:CUBRID:127.0.0.1:31000:db1:::?althosts=127.0.0.2:31000,127.0.0.3:31000&rctime=600&charset=utf-8

Example 2

String url = "jdbc:cubrid:210.216.33.250:43300:demodb:::";

String userid = "";

String password = "";

 

try {

   Connection conn =

           DriverManager.getConnection(url,userid,password);

   // Do something with the Connection

 

   ...

 

   } catch (SQLException e) {

       System.out.println("SQLException:" + e.getMessage());

       System.out.println("SQLState: " + e.getSQLState());

   }

   ...

Note The rollback function, which requests the transaction rollback, exits when the server completes the work.