Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

JDBC Driver detection error when running as Windows Service

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me describe the setup first. I am uisng JDK 1.3. The classes12.jar (JDBC driver) has been placed in C:\jdk1.3\jre\lib\ext folder, so I have not explicitly added the jar to the classpath. My test program can make a JDBC connection fine from this windows machine to Oracle. Now, I create a jar of this code and the windows service basically loads the jar up when Windows starts. When run in this manner, I get ClassNotFoundException for "oracle.jdbc.driver.OracleDriver". However, I have a bat file that starts the jar up the same way (java -jar ReportServer.jar) and that seems to be able to make JDBC connections just fine. Below is a code excerpt being used for the connection:

......
DriverManager.registerDriver((Driver)Class.forName("oracle.jdbc.driver.OracleDriver").newInstance());
//Get a Connection to the database
myConn = DriverManager.getConnection(dbUrl, rptUsername, rptPassword);
.........

I am catching all the required exceptions etc.

Also, here's how the environment variables are set:
JAVA_HOME=C:\jdk1.3
Path=D:\apache;C:\jdk1.3\bin;D:\Oracle\Ora81\bin;.............
CLASSPATH=.;D:\Oracle\Ora81\bin;C:\jdk1.3;.....................

Any ideas? I dont know what I am doing wrong. This needs to run as a windows service. Thanks!
 
author & internet detective
Posts: 41073
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Abhijit,
Welcome to JavaRanch!

While this post does relate to JDBC, I'm moving it to our General Computing forum because it is more about classpaths on window services (since the batch file works)
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Firstly

is not correct and can cause the Driver to be registered twice. This is only a problem if you try to remove Drivers (whcih I've never seen anyone do), but this is the preferred mechanism:


While it doesn't look like it does anything, the ClassLoader loads the Driver and as the Driver loads it is required to register itself with the DriverManager.

Have you tried taking the classes12.jar out of the lib/ext directory and getting the batch file to include it? There is a strange security ussue relating to the way Drivers get loaded, but I'm trying to remeber the ways to recreate the problem and how to solve it. the 'lib/ext' directory doesn't feel like the right place for it.

Sorry for being so vague :}

Dave
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic