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
  • 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.

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..

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.


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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now