JDBC connectivity without mentioning DSN

hi Freinds,,

   i am in a big trouble now. My java programme needs the connectivity to oracle,informix,ms access databases. but i don't know the correct dsn's for that. i heard that this can be possible by using pure JDBC driver without using the jdbc:odbc bridge.but i am confused with that..can u guys help me with that..

thanks in advance,

Who is Participating?
kvkameshConnect With a Mentor Commented:
This is 100% answer for your question. To connect to the Oracle database try this example. you have to download the orcale type 4 driver "classes111.zip" file from www.otnxchange. and set the path in your system like this. say you have jdk in C drive. c:\jdk1.2.2\lib\classes111.zip.

output of the below program will give you number of records in emp table.

import java.sql.*;
class ConnectToOracle {

static final String driver_class = "oracle.jdbc.driver.OracleDriver";
static final String driver_type = "jdbc:oracle:thin";

static final String user_name      = "scott";
static final String pass_word      = "tiger";
static final String host_name      = "";
static final String port_number = "1521";
static final String data_base      = "orcl";
static final String table_name      = "emp";

static final String connect_string = driver_type +":"+ user_name +"/"+ pass_word +"@"+ host_name +":"+ port_number +":"+ data_base;

public static void main(String argv[])

Connection conn = DriverManager.getConnection(connect_string);

Statement stmt = conn.createStatement();

String sqlCommand = new String("SELECT count(*) from " + table_name);

ResultSet rs = stmt.executeQuery(sqlCommand);

 while (rs.next())

 int rcount = rs.getInt(1);
 System.out.println(rcount + " records in " + table_name);
 catch( Exception e )
YOu have to use different drivers to connect different databases.
Informix you have to use weblogic Jdriver
Connecting to an Informix DBMS

The following steps tell you how to set up your application to connect to Informix using WebLogic jDriver for Informix. In general, connecting happens in three steps:

Load the JDBC driver by calling Class.forName().newInstance() with the full class name of the WebLogic jDriver for Informix JDBC driver class, and casting it to a java.sql.Driver object. This procedure properly loads and registers the JDBC driver. For example:

Driver myDriver = (Driver) Class.forName("weblogic.jdbc.informix4.Driver").newInstance();

Create a java.util.Properties object describing the connection. This object contains name-value pairs containing information such as user name, password, database name, server name, and port number. For example:

Properties props = new Properties();props.put("user",         "scott");props.put("password",     "secret");props.put("db",           "myDB");props.put("server",       "myHost");props.put("port",         "8659");

Create a JDBC Connection object, which becomes an integral piece in your JDBC operations, by calling the Driver.connect() method, which takes as its parameters the URL of the driver and the java.util.Properties object you created in step 2. For example:

Connection conn =    myDriver.connect("jdbc:weblogic:informix4", props);

In steps 1 and 3, you are describing the JDBC driver: in the first step, you use the full package name of the driver. Note that it is dot-delimited. In the third step, you identify the driver with its URL, which is colon-delimited. The URL must include at least weblogic:jdbc:informix4, and may include other information, including the server host name and the database name.
For MS access you can'not connect to with type 4 driver.

i think you have clear understanding now.
You have to accept it. this is 100% answer for you Question.
I dont think you have a pure JDBC driver for MS Access. For this case you will have to use JDBC-ODBC. I am sure  Oracle has a JDBC driver but have no idea about Informix. With the Oracle JDBC drivers all you need to specify is the database name, connect string, userid and password and JDBC will use SQL*Net to connect to the Oracle database without needing to go through ODBC.
Write a DataAccess class which relies on a properties file to configure the JDBC driver name and the database URL. Put the connection logic inside the DataAccess class. You can deploy the same code and use a different properties file for each configuration. I did this in the project we are now working on - I prototyped it in Access and did later development in Informix. The Informix JDBC driver does not handle the database URL the same way that Oracle and Access do, so you are better off putting the entire URL in your properties file instead of separate properties for user, password, port, etc.

Good luck

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

use oracle thin jdbc type 4 driver. In this there is no need to use DSN name. simple use the fallowing parameters jdbc:oracle:thin:usename/scott@hostname:portnumber:sid, this is for oracle.
use oracle thin jdbc type 4 driver. In this there is no need to use DSN name. simple use the fallowing parameters jdbc:oracle:thin:usename/password@hostname:portnumber:sid, this is for oracle.
jimaricat072100Author Commented:
hi tony..

  i desperately need the help for Access,Oracle nd Informix. i accept u'r answer..but i am still waiting for a good one whic can suit these three databases.

thank you for u'r support..

You need to write a data access class to handle the connection. You need to download JDBC drivers for every database you intend to support. I don't think the Oracle thin driver will work for other databases, because I believe it only works on Oracle. You may be stuck with the JDBC/ODBC bridge for MS Access, but this is the slowest driver so you don't want to use it for your database access unless you have no alternative.

Your data access class needs to be able to set the database URL and database driver class file name dynamically. A properties file is probably the easiest way to go. Then you can compile the data access source code and use the same java class files for every database installation, only changing the properties file.

Here is a bit of code to get you started -

      // we have written a Property Manager class; the "pm"
      // reference is to an instance of this property manager.
      // We also have a boolean flag DEBUG_ON which we
      // turn on during development and off when deploying.

      // The reference is to Informix, because that is what we
      // are using, however this bit of code should work with
      // Oracle and Access as well, provided their JDBC drivers
      // allow you to specify the database URL string, rather
      // than setting individual properties like user name, password,
      // etc.

      // Your database driver jar files have to be in your class
      // path, or you will get a Class Not Found error.

       String URLString = (String) pm.getProperty("DatabaseURL");
       String ifxDriver = (String) pm.getProperty("DriverName");

         System.out.println("Connection from: " + URLString);

         // Register the INFORMIX-JDBC driver
       Driver IfmxDrv = (Driver) Class.forName(ifxDriver).newInstance();
       if(IfmxDrv == null)
         System.out.println("Driver null.");

      // Get a connection to the database server
       _conn = DriverManager.getConnection(_URLString);

       if(_conn == null)
           throw new Exception("Attempted database connnection failed.");


jimaricat072100Author Commented:
thanks for accepting my answer and solving your probelm. i have 4 years experience in IT field you can ask me any Q?, i will give you exact answer not comment.thank you kamesh
jimaricat072100Author Commented:
Hi kamesh,..

Thanks for u'r invitation. I will try to contact u once i could get u'r mail id.

Regarding the answer,..one more doubt,..please..

above said answer is only for oracle right..?
Is this the same for anyother databases.Should we have to download thier own thin drivers,...?

Expecting from u soon..

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.