Link to home
Start Free TrialLog in
Avatar of jimaricat072100
jimaricat072100Flag for Kuwait

asked on

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,

Jim
Avatar of tonyjohn
tonyjohn

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

Dorothy
HI
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.
HI
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.
Avatar of jimaricat072100

ASKER

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

Jim
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");

       setURLString(URLString);
       if(DEBUG_ON)
         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.");

Dorothy

ASKER CERTIFIED SOLUTION
Avatar of kvkamesh
kvkamesh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks KVKAMESH
hi
Jimaricat
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
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..

Jimmy