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 Cannot register driver 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 "Cannot register driver" Watch "Cannot register driver" New topic
Author

Cannot register driver

Mujahid Al-okaidi
Greenhorn

Joined: May 31, 2008
Posts: 8
Hi there

I have an application that works fine when I run it from the eclipse IDE but when I exported it to a jar file and execute the jar it dosent go past the line:

OracleDriver driver = new OracleDriver();

It dosen't throw an exception it just stays there forever.

any idea why that is?
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1082

Can you post the code of method, where you are facing this problem.

Do you have OracleDriver in your run-time path, when you run your application as jar ?


Thanks,
Shailesh


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3740
    
  10

That's not the way you initialize a driver. Have you tried JDBC tutorials for oracle? Could you post all of your initialization code.
[ August 18, 2008: Message edited by: Scott Selikoff ]

[OCA 8 Book] [Blog]
Mujahid Al-okaidi
Greenhorn

Joined: May 31, 2008
Posts: 8
This is the method and executes fine as I said but when I export it to a jar it stops at line (1) and doesn't throw an exception.

note: Message is a JFrame that will display the arguments I added it for debugging as System.out.println doedn't give an output from an executable jar.

Thanks


private void connect() throws SQLException
{
Message.setText("Connecting");
try
{
OracleDriver driver = new OracleDriver(); //(1)
Message.setText("Trying");
DriverManager.registerDriver (driver);
}
catch(Exception e)
{
Message.setText(e.getMessage());
}
Message.setText("past exception");
connection = DriverManager.getConnection("jdbcracle:thin:@oracle.*****.com:1521:campus","*****", "*****");
Message.setText("Connected");
connected = true;
}
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19693
    
  10

Then presumably you haven't set up your jar file in such a way that the driver is in its classpath. Are you running the jar as an executable jar? If so, what's in the Class-Path entry in its manifest?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14916
    
  26

I don't know what the exact cause is of your bug, but to echo what Scott said:

OracleDriver driver = new OracleDriver();
DriverManager.registerDriver (driver);


This is not the correct way to initialize the JDBC driver. You're not supposed to register the driver yourself with the DriverManager. Instead of the above two lines, you should do something like this:

Class.forName("oracle.jdbc.driver.OracleDriver");


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Mujahid Al-okaidi
Greenhorn

Joined: May 31, 2008
Posts: 8
Originally posted by Paul Clapham:
Then presumably you haven't set up your jar file in such a way that the driver is in its classpath. Are you running the jar as an executable jar? If so, what's in the Class-Path entry in its manifest?



I am running the a jar and I think the problem could be the mainfest file, I have listed the ontents of the file, please let me know what I need to add.

Manifest-Version: 1.0
Sealed: true
Main-Class: Main

Thanks
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Working with Manifest Files: The Basics

Originally posted by Mujahid Al-okaidi:



I am running the a jar and I think the problem could be the mainfest file, I have listed the ontents of the file, please let me know what I need to add.

Manifest-Version: 1.0
Sealed: true
Main-Class: Main

Thanks


Regards, Rene Larsen
Dropbox Invite
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Cannot register driver
 
It's not a secret anymore!