O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required