Tutorials : Building Web Applications Using Servlets and JSP :

There are some distinct steps in accessing a database using JDBC.

STEP 1: Make a connection

This Step involves the driver setup and loading. Hence it is dependent on the type of driver you are using. To make a connection with the Database, we first

  • Load the driver
  • Get a connection using this driver

Load The driver

If you are using the Sun JDBC-ODBC bridge :

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

If you are using any other driver please refer to Appendix A for a sample code for loading Oracle driver. The code for loading any other JDBS driver will be similar.

The forName Method will create an instance of a driver and register it with the DriverManager.

Get a connection using this driver

The Generic code is:

Connection con = DriverManager.getConnection(url,
                     "myLogin", "myPassword");

url: If you are using JDBC-ODBC bridge then url will look like:

String url = jdbc:odbc:myDriver

Where myDriver is the Data Source Name of the ODBC driver to connect to your database.

If you are using any other driver please refer to Appendix A for an example of how "url" will look.

The Connection returned (con) in the previous example is an 'open' connection which we can use to send SQL data over.

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.