The DriverManager is a basic interface 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, and password) method. The getConnection method 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> | connectTimeout=<second> | queryTimeout=<second> | charset=<character_set> | zeroDateTimeBehavior=<behavior_type> | logFile=<file_name> | logOnException=<bool_type> | logSlowQueries=<bool_type>&slowQueryThresholdMillis=<millisecond>
<alternative_hosts> ::=
<standby_broker1_host>:<port> [,<standby_broker2_host>:<port>]
<behavior_type> ::= exception | round | convertToNull
<bool_type> ::= true | false
For information on the value having 0 for both date and time, see "CUBRID SQL Guide > Data Types > Date/Time Types > Definition and Characteristics."
--connection URL string when user name and password omitted
URL=jdbc:CUBRID:192.168.0.1:33000:db1:::
--connection URL string when zeroDateTimeBehavior property specified
URL=jdbc:CUBRID:127.0.0.1:31000:db1:::?zeroDateTimeBehavior=convertToNull
--connection URL string when charset property specified
URL=jdbc:CUBRID:192.168.0.1:33000:db1:::?charset=utf-8
--connection URL string when queryTimeout and charset property specified
URL=jdbc:CUBRID:127.0.0.1:31000:db1:::?queryTimeout=1&charset=utf-8
--connection URL string when a property(althosts) specified for HA
URL=jdbc:CUBRID:192.168.0.1:33000:db1:::?althosts=192.168.0.2:33000,192.168.0.3:33000
--connection URL string when properties(althosts,rctime) specified for HA
URL=jdbc:CUBRID:192.168.0.1:33000:db1:::?althosts=192.168.0.2:33000,192.168.0.3:33000&rctime=600
--connection URL string when properties(althosts,rctime, charset) specified for HA
URL=jdbc:CUBRID:192.168.0.1:33000:db1:::?althosts=192.168.0.2:33000,192.168.0.3:33000&rctime=600&charset=utf-8
String url = "jdbc:cubrid:192.168.0.1:33000: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());
}
...
Because a colon (:) and a question mark (?) are used as a separator in URL string, it is not allowed to include them for password of URL string. To use them, you must specify a user name (user-id) and a password (password) as a separate parameter in the getConnection method.
Note The rollback method, which requests the transaction rollback, exits when the server completes the rollback job.