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 Error in No suitable driver found for jdbc:postgresql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Error in No suitable driver found for jdbc:postgresql" Watch "Error in No suitable driver found for jdbc:postgresql" New topic
Author

Error in No suitable driver found for jdbc:postgresql

reubin haz
Ranch Hand

Joined: May 12, 2005
Posts: 287
I'm using Eclipse to build a program. There is one class that connects postgresql DB, and I have included postgresql-8.3-604.jdbc3.jar in the Java build path. There is no compilation error appearing in Eclipse. There is also no compilation error when I build it using ant. But when I try to run the generated runnable Jar file. Then it starts to complain:

error in SQLException>>>java.sql.SQLException: No suitable driver found for jdbc:postgresql://........

Can someone help me solve this? Thanks.

SCJA, SCJP5.0, SCBCD, SCWCD
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Have you loaded the driver class? You need to call this line to do that (actual class name may differ, but probably doesn't):


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
reubin haz
Ranch Hand

Joined: May 12, 2005
Posts: 287
Yes, I did, and that's where the problem begins...
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
reubin haz wrote:run the generated runnable Jar file

Is the driver in the classpath of the runtime environment of that JAR file?

According to the exception you're not loading the driver at all, or you're suppressing any ClassNotFoundException of the driver (you shouldn't be doing that, it would only lead to misleading exceptions which come after), or the URL is actually wrong (after a quick scan of PostgreSQL JDBC docs the jdbc:postgresql prefix is just fine).
reubin haz
Ranch Hand

Joined: May 12, 2005
Posts: 287
Bauke Scholtz wrote:
reubin haz wrote:run the generated runnable Jar file

Is the driver in the classpath of the runtime environment of that JAR file?


I think this is where the problem comes from. But I don't know how to check this. Please help.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41082
    
  43
Apparently the classpath used for running the code is different from the classpath used for compiling it.


Ping & DNS - my free Android networking tools app
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
reubin haz wrote:I think this is where the problem comes from. But I don't know how to check this. Please help.

That fully depends on how exactly you execute the JAR and how the manifest of the JAR look like.
reubin haz
Ranch Hand

Joined: May 12, 2005
Posts: 287
Could you tell me how a JAR program is normally setting up the classpath for runtime?

Thanks.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Either using java's -cp or -classpath argument or using the class-path entry in JAR's manifest file.
reubin haz
Ranch Hand

Joined: May 12, 2005
Posts: 287
Thanks Bauke. I got it.
 
Don't get me started about those stupid light bulbs.
 
subject: Error in No suitable driver found for jdbc:postgresql
 
Similar Threads
java -jar [error] unable to access jarfile postgresql-8.4-702.jdbc.3.jar
ant junit task cannot find driver on classpath
Exception in example Using Hibernate Entity Manager in 2nd chapter of Java Persistence WithHibernate
Hibernate and Postgresql