JDBC connectivity without mentioning DSN

Posted on 2001-06-23
Last Modified: 2008-03-17
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,

Question by:jimaricat072100
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1

Expert Comment

ID: 6221080
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.

Expert Comment

ID: 6223047
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


Expert Comment

ID: 6227398
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.
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.


Expert Comment

ID: 6227400
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.

Author Comment

ID: 6230037
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..


Expert Comment

ID: 6231368
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.");



Accepted Solution

kvkamesh earned 250 total points
ID: 6234645
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 "" 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\

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 (

 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.

Author Comment

ID: 6247365

Expert Comment

ID: 6248237
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

Author Comment

ID: 6251303
Hi kamesh,..

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

Regarding the answer, 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..


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question