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 the fly likes JDBC Connection Problem when I put my code in a package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC Connection Problem when I put my code in a package" Watch "JDBC Connection Problem when I put my code in a package" New topic
Author

JDBC Connection Problem when I put my code in a package

Steve Schavrien
Greenhorn

Joined: Oct 24, 2007
Posts: 3
In advance I'd like to thank you for your comments and suggestions.
First I will give a brief summary of my problem, a code snippet, and then add some specific environment settings etc.

On an HP-UNIX machine with Oracle 10g I created a path setting to $ORACLE_HOME/jdbc/lib went to my playpen directory.
I created a simple TestDB.java program for connecting to a database and then spit out the results of a query.
This worked fine and I created some src and bin directories with the proper directory structure to match the package names.
I get the dreaded 'No suiteable Drive' after running the code in the package. any help sould be greatly appreciated

code snippet:
package org.hphc.temp;
....
62 public static Connection getConnection()
63 throws SQLException, IOException
64 {
65 String drivers = "oracle.jdbc.OracleDriver";
66 System.setProperty("jdbc.drivers", drivers);
67 String url = "jdbcracle:thin:@hostname.company.org:port:sid";
68 String username= "xxxxxx";
69 String password= "xxxxxx";
70 // return java.sql.DriverManager.getConnection(url, username, password);
71 return DriverManager.getConnection(url, username, password);
72 }
73
74 }
../exper_java/ecare/src/org/hphc/temp $ cd -
../exper_java/ecare
../exper_java/ecare $ javac -d bin -sourcepath src src/org/hphc/temp/TestDB.java
../exper_java/ecare $ java -classpath bin org/hphc/temp/TestDB
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:532)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at org.hphc.temp.TestDB.getConnection(TestDB.java:71)
at org.hphc.temp.TestDB.runTest(TestDB.java:21)
at org.hphc.temp.TestDB.main(TestDB.java:15)

The code works fine in directory ../exper_java, the code has not package name and use straight javac pgm.java and java pgm.

I do hove $ORACLE_HOME/jdbc/lib in my path via unix .profile
I have tried fully qualify and using java -classpath bin;$ORACLE_HOME/jdbc/lib org/hphc/temp/TestDB

Again, Any help would be greatly appreciated!
Emanuel Kadziela
Ranch Hand

Joined: Mar 24, 2005
Posts: 186
Sounds like a classpath problem. Make sure the driver location is in the classpath and reachable from where you execute your code.
Steve Schavrien
Greenhorn

Joined: Oct 24, 2007
Posts: 3
Thanks for your reply Emanuel. That's what I thought and tried a few things as stated before:

I do have $ORACLE_HOME/jdbc/lib in my path via unix .profile
I have tried fully qualify and using java -classpath bin;$ORACLE_HOME/jdbc/lib org/hphc/temp/TestDB

I was proto typing and just took out using packages for now. Whenever I revisit this issue, I 'll post the solution. It just seemed odd that specifing the classpath at runtime did not help. Maybe there is something incorrect about my driver path.: $ORACLE_HOME/jdbc/lib
Steve Schavrien
Greenhorn

Joined: Oct 24, 2007
Posts: 3
Ok, I'll have to check what the issue was in my .profile and my PATH.

I simply hunted around and discovered on HP-UNIX the classpath seperator is a full colon. Then I fully qualified and it worked.

java -classpath bin:$ORACLE_HOME/jdbc/lib/classes12.jar:
[ November 19, 2007: Message edited by: Steve Schavrien ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC Connection Problem when I put my code in a package