File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and Relational Databases and the fly likes Cant Connect to Oracle via JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Cant Connect to Oracle via JDBC" Watch "Cant Connect to Oracle via JDBC" New topic
Author

Cant Connect to Oracle via JDBC

Art Smith
Ranch Hand

Joined: Dec 12, 2000
Posts: 33
Hi,
I have a Java app that needs to query an oracle database. I developed the app under JBuilder 4 and it connects the database just fine.
But, when I try to run outside of JBuilder I 'm getting the following error:
Specified Driver could not be loaded due to system error 126 (Oracle ODBC Driver)
TIA,
Art

Arthur Smith<br />SCJP2 - SCWCD
Robert Brunner
Ranch Hand

Joined: Jul 18, 2001
Posts: 49
Need more information to really dignose what is going on. It looks like you are using the JDBC-ODBC bridge to connect to your Oracle database. If so, have you registered the ODBC DSN on the system you are running the java code?
I would suggest you try Oracle's (or some 3-party vendor's) JDBC driver. The thin driver can be downloaded diurectly from technet.
Art Smith
Ranch Hand

Joined: Dec 12, 2000
Posts: 33
Yes I am using the JdbcOdbc bridge. I assumed I had to since my app is running on NT.
Here is the offending code:
public void connectTODatabase() throws SQLException, ClassNotFoundException, Exception {
Class.forName(driver); // Attempt to Load the Specified Driver
con = DriverManager.getConnection(url,username,password); // Get a connection to the Database via the Driver
if (con.isClosed()) {
throw new Exception("Connection to Specified Database could not be opened");
}
if (debug) {
System.out.println("Driver :"+url+"\n");
System.out.println("Connected :"+url+"\n");
}
createStatement();
}
Any suggestions would be helpfull. I've got to get this thing into production this week.
Art
Art Smith
Ranch Hand

Joined: Dec 12, 2000
Posts: 33
Opps. I forgot to mention that the exception I'm getting in an SQLException. NOT a ClassNotFoundException.
Again the error message is:
Specified Driver could not be loaded due to system error 126 (Oracle ODBC Driver)
Robert Brunner
Ranch Hand

Joined: Jul 18, 2001
Posts: 49
A couple of things, (1) what are the values for driver, url ? (2) Are you sure the DSN is set up properly?, and (3) are you sure the Oracle ODBC driver is installed?
To help, I need the values indicated in (1), e.g., jdbc.odbc.myOracleDatabase would be a possible value for the JDBC url. For (2) you would need to have registered the DSN myOracleDatabase using Windows ODBC administrator (odbcad32.exe, which is located in C:\WINNT\system32). Finally, Oracle has an ODBC test tool. I beleive it is installed under start->programs->oracle home (?)->newtork administration
Hope this helps.
Art Smith
Ranch Hand

Joined: Dec 12, 2000
Posts: 33
After talking to folks at the office I discovered that I could use the Oracle JDBC driver instead of the ODBC/JDBC driver I used durning the development phase of the project.
I've since implemented my app using the Oracle JDBC drivers. I like this solution better cause I don't have to install anything on the server where my app lives. Just drop the Oracle drivers zip file in my class path and I'm good to go. Plus, I don't have to maintain a DSN on the server of ODBC - one less thing to remember if we get a new machine or something.
So, to those who took the time to reply to my query.
THANKS,
Art
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cant Connect to Oracle via JDBC
 
It's not a secret anymore!