A.18. JDBC and Database Connection Pooling
Basic Steps in Using JDBC
Load the JDBC driver. See http://java.sun.com/products/jdbc/drivers.html for available drivers. Example:
Class.forName("package.DriverClass"); Class.forName("oracle.jdbc.driver.OracleDriver");
Define the connection URL. The exact format will be defined in the documentation that comes with the particular driver.
String host = "dbhost.yourcompany.com"; String dbName = "someName"; int port = 1234; String oracleURL = "jdbc:oracle:thin:@" + host + ":" + port + ":" + dbName; String sybaseURL = "jdbc:sybase:Tds:" + host + ":" + port + ":" + "?SERVICENAME=" + dbName;
Establish the connection.
String username = "jay_debesee"; String password = "secret"; Connection connection = DriverManager.getConnection(oracleURL, ...
Get Core Servlets and JavaServer Pages™ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.