JDBC Database URL

JDBC Database URL

Posted in : Core Java Posted on : October 15, 2010 at 5:45 PM Comments : [ 0 ]

This section contains the detail about the basic operators in java.

JDBC Database URL

In this Section, We will discuss about following topics :

  • JDBC Database URL
  • Specify a JDBC driver name
  • Connection to a database table

JDBC Database URL

JDBC Uniform resource locater or 'JDBC URL'  is used to identify a database using a unique name or address. All database should be connect to database using these URL strings. Format of JDBC URL :


In this URL string, the first string "jdbc" represents the protocol name, "subprotocol" represents the type of database you want to connect .Example-jdbc, oracle, Mysql. While "subname " provide additional information like host name or machine name, port, database name or instance etc.

URL'S Example :

  • JDBC ODBC Bridge driver:
  • Oracle JDBC Driver(TYPE 4) :
  • Mysql Connector JDBC driver

Note: You can Download Mysql Connector From the site "http://dev.mysql.com/downloads/connector/j/". You have to paste it in "lib" folder of "jdk" directory.

Specifying a  JDBC Driver Name

To load driver before  connection , you must know the full class name of your JDBC driver. We can load driver in two different ways, theses are :

Way-1: To load the the driver/s at JVM startup, specify the driver/s in jdbc.drivers system property like this:

       java -Djdbc.drivers=com.mysql.jdbc.Driver YourJavaProgram

Way-2: To load driver explicitly, use Class.forName() method like this :


Connection to a database table

For connecting to a database, You must import  "java.sql.*" package. After loading Driver  implicitly or explicitly, as mention above. You will have to create connection with the help of "getConnection() " method using "Connection" interface object. In "getConnection()" method you have to pass "JdbcURL" of the type of Database you want to connect. After creating connection,  Queries will be run with the help of  "createStatement ()"  method using "Statement" or "PrepareStatement" object.

Example: JdbcUrl.java

In this code, we load the  JDBC driver at JVM startup without using "Class.forName()"  :







//declare√?¬†a√?¬†resultset√?¬†that√?¬†uses√?¬†as√?¬†a√?¬†table for√?¬†output√?¬†data√?¬†

√?¬† while√?¬†(rs.next())√?¬†{



C:\Program Files\Java\jdk1.6.0_18\bin> java -Djdbc.drivers=com.mysql.jdbc.Driver JdbcUrl
Showing row of student table
2147483647   Ankit        1985-06-06

2147483647   Somesh    1984-05-05

Download Source code

Go to Topic «PreviousHomeNext»

Your Comment:

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image

Tutorial Topics