Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in No suitable driver found for jdbc:postgresql

 
reubin haz
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20751
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you loaded the driver class? You need to call this line to do that (actual class name may differ, but probably doesn't):
 
reubin haz
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I did, and that's where the problem begins...
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apparently the classpath used for running the code is different from the classpath used for compiling it.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you tell me how a JAR program is normally setting up the classpath for runtime?

Thanks.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either using java's -cp or -classpath argument or using the class-path entry in JAR's manifest file.
 
reubin haz
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bauke. I got it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic