• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Connecting To Database

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 jdbc:odbc: is the ODBC Data Source Name (DSN), not the Oracle SID.

Jules
 
Greedy thomas
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author
Posts: 531
Mac OS X Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greedy thomas
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
On my planet I'm considered quite beautiful. Thanks to the poetry in this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic