Connecting to a Database via JDBC

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
											Connection conn =
											DriverManager.getConnection(url, user, password);

To make a database connection using JDBC, you first have to load a driver. In this phrase, we load the JdbcOdbcDriver. This driver provides connectivity to an ODBC data source. We load the driver using the Class.forName() method. Database JDBC drivers are generally provided by database vendors, although Sun does provide several generic drivers such as the ODBC driver that we use in this phrase. After we have the driver loaded, we get a connection to the database using the DriverManager.getConnection() method. We use a URL-like syntax to specify the database that you want to connect to. We also pass ...

Get Java™ Phrasebook 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.