Re: Not able to connect to postgresql database
От | Lew |
---|---|
Тема | Re: Not able to connect to postgresql database |
Дата | |
Msg-id | hu45l7$d93$1@news.albasani.net обсуждение исходный текст |
Ответ на | Re: Not able to connect to postgresql database ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>) |
Ответы |
Re: Not able to connect to postgresql database
|
Список | pgsql-jdbc |
On 06/01/2010 04:27 PM, Kevin Grittner wrote: Manohar Bhattarai wrote: > >> shows an exception that it cannot find driver. > >> Please help me and let me know what i am doing wrong and what i am >> missing. > > The jar is not on your classpath, or you are not spelling the class > name ("org.postgresql.Driver") correctly. I don't know of any other > reason that the recommended class loading: > > Class.forName("org.postgresql.Driver"); Just as an aside, nowadays the recommended way from Sun is to load a driver is through DataSource descriptors, which has its advantages but is a lot less simple at first. With JPA you configure the data source in the "persistence.xml" file for a local application, other XML files like "context.xml" for app servers. The 'Class.forName()' method is reliable but don't fall into the trap of calling it more than once per program execution. > would throw a ClassNotFoundException. (If that's not what you're > doing, or that's not the statement on which it fails, or that's not > your exception, you need to give us more clues.) All techniques require proper placement of the driver JAR file in your classpath. What that classpath is depends utterly on how you package and deploy your app. There's clear documentation on java.sun.com about JDBC, and about how to specify the classpath for the "java ... foo.foo" ("-classpath" option) and "java -jar foo.jar" (manifest file "Class-path:" entry) commands. For the various app servers you have to check the rules for the particular app server, e.g., <http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html> -- Lew
В списке pgsql-jdbc по дате отправления: