aspose file tools*
The moose likes JDBC 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
Bookmark "Connecting To Database" Watch "Connecting To Database" New topic
Author

Connecting To Database

Greedy thomas
Ranch Hand

Joined: May 15, 2003
Posts: 37
Hello

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,
Rajesh





java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6879)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7036)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3028)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at TestConnect.main(TestConnect.java:12)
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.

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

Thanks,
Rajesh
Masoud Kalali
Author
Ranch Hand

Joined: Jul 08, 2004
Posts: 531

Hi
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.
DBDriver("oracle.jdbc.driver.OracleDriver");
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.

Regards,
Rajesh
 
 
subject: Connecting To Database