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 |
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, 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>]
--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
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.