File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Connecting To Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Connecting To Database" Watch "Connecting To Database" New topic

Connecting To Database

Greedy thomas
Ranch Hand

Joined: May 15, 2003
Posts: 37

I'm having problems connecting to the databse via a java program. I'm using Win 98 and Oracle 9i Personal Edition. The database is on the same machine as the code. Accessing the data via SQL Plus works fine.

The database is mounted and ready. I tried using the following program but get the error listed below. Do I need to create a new datasource using Start -> Settings -> ODBC Data Sources or what is the datasource that has been provided with Oracle 9i.

Also in the url for the getConnection, do I use the sid value in here e.g my sid is Rajesh so do I use "jdbc dbc:Rajesh"

Please help.

Thanks in advance,

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(
at sun.jdbc.odbc.JdbcOdbc.standardError(
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(
at sun.jdbc.odbc.JdbcOdbcDriver.connect(
at java.sql.DriverManager.getConnection(
at java.sql.DriverManager.getConnection(
at TestConnect.main(
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
If you want to use the JDBC/ODBC bridge drive then you'll need to create an ODBC DSN as you suggest. I would personally recommend using an Oracle JDBC driver. There may be one included with your installation. If not you can download one for free from Oracle's website. The bit after jdbcdbc: is the ODBC Data Source Name (DSN), not the Oracle SID.

Greedy thomas
Ranch Hand

Joined: May 15, 2003
Posts: 37
Thanks Julian

How do I find out what Oracle drivers has been included in my installation. Also, how do I find out the Oracle Data Source Name and what should I use.

Please excuse my ignorance but I'm new to this side of programming.

Masoud Kalali
Ranch Hand

Joined: Jul 08, 2004
Posts: 531

certainly JDBC driver is installed in your machine when you install Oracle
check for a folder named JDBC in your installation directory
inside jdbc you can find a LIB directory which contains all required jar files
put [oracle 9i2] %Oracle_home%\jdbc\lib\ojdbc14.jar in your class path
when Oracle_home is where u installed Oracle.

DatabaseName is what you entered during installation as SID -AFAIR-
for example a connection String could be like this :

ConnectionURL("jdbc racle:thin:@localhost:1521:thedb");

and driver class name like this.
other stuff like username and password go similar to all jdbc drivers.

hope it helps.

Masoud Kalali
Software Engineer - My Weblog - GlassFish Security
Greedy thomas
Ranch Hand

Joined: May 15, 2003
Posts: 37
Thanks Masoud

I've tried what you had suggest but still seem to be running into problems. Please help guys.

The JDBC directory exists in C:\ORACLE\ORA90. Within the LIB directory I have classes111.jar and classes12.jar.

I have the following in my autoexec.bat file :
SET path="C:\Program Files\Oracle\jre\1.1.8\bin";"%path%";
SET Path=c:\oracle\ora90\bin;"%Path%"

My computer name (from Start -> Settings -> Control Panel -> Network : Identification Tab - Computer Name Field = Computer)

My database name (SID) is rajesh.

Do I need to create any environment variables. I have Oracle 9.0.1 and am using Windows 98.

What do you mean by
>> put [oracle 9i2] %Oracle_home%\jdbc\lib\ojdbc14.jar in your class path
What is [oracle 9i2]? Does the class path you refer to mean the SET path I have above.

When I run the following code, it fails with 'Failed to load driver'

Also, when do you use "OCI" and when do you use "THIN".

Please help - I really need to get this going.

Thanks you for all your help.

I agree. Here's the link:
subject: Connecting To Database
It's not a secret anymore!