Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Retrieving Data - a Simple JDBC Example

June 12, 2000

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.

JDBC a Brief Introduction
Building Web Applications Using Servlets and JSP Part II
STEP 2: Use This Connection to Access the Database


Up to => Home / Authoring / Java / Servlets




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers