The DriverManager.getConnection() method
To create a connection to the HCL OneDB™ database or database server, you can use the DriverManager.getConnection() method. This method creates a Connection object, which is used to create SQL statements, send them to the HCL OneDB database, and process the results.
The DriverManager class tracks the available drivers and handles connection requests between appropriate drivers and databases or database servers. The url parameter of the getConnection() method is a database URL that specifies the subprotocol (the database connectivity mechanism), the database or database server identifier, and a list of properties.
A second parameter to the getConnection() method, property, is the property list. See Specify Connection Properties for an example of how to specify a property list.
jdbc:onedb://123.45.67.89:1533/testDB;user=onedbsa;password=onedbsapassword
The details of the database URL syntax are described in the next section.
try { conn = DriverManager.getConnection(url); } catch (SQLException e){ System.out.println("ERROR: failed to connect!"); System.out.println("ERROR: " + e.getErrorCode()); e.printStackTrace(); }
Client applications should close the connection when it is finished its work with the database. To improve performance a connection pool can be used to manage reusable connections to the database.