Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot register driver

 
Mujahid Al-okaidi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Scott Selikoff
author
Saloon Keeper
Posts: 4010
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Mujahid Al-okaidi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20966
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
 
Mujahid Al-okaidi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic