Why is the player playing with "Driver not found: [org.postgresql.Driver]"?

This is my application.conf:

db.default.driver=org.postgresql.Driver db.default.url="postgres://postgres: postgres@localhost :5432/postgres" db.default.user="postgres" db.default.password= "postgres" 

I downloaded postgresql-9.1-902.jdbc4.jar. Included it in your jar files, adding it as an external jar. However, this shows me this error that the driver was not found. Help?

+4
source share
2 answers

I would say that the PostgreSQL driver is not really in your classpath, but since you did not specify the exact text of the error message, it’s hard for you to be sure. This will help if you can (a) show the exact copied and pasted text of the full error message and trace; and (b) indicate exactly where you put the PgJDBC jar.

Consider adding debugging code that displays the contents of System.getProperty("java.class.path") during the launch of your application. Also add a block that will do something like:

 try { Class.forName("org.postgresql.Driver") } catch (ClassNotFoundException ex) { // Log or abort here } 

That should say something about class visibility. Due to the complexity of loading classes on modern JVMs and frameworks, this will not be final - there are too many cool downloaders.

+6
source

I am using postgresql 9.1-901.jdbc4 in my project and I configured it as follows:

Build.scala:

 import sbt._ import Keys._ import PlayProject._ object ApplicationBuild extends Build { val appName = "project_name" val appVersion = "1.0-SNAPSHOT" val appDependencies = Seq( // Add your project dependencies here, "postgresql" % "postgresql" % "9.1-901.jdbc4" ) val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings( // Add your own project settings here ) } 

application.conf

 db.default.driver=org.postgresql.Driver db.default.url="jdbc:postgresql://localhost:5432/project_name" db.default.user=postgres db.default.password=mypw db.default.partitionCount=1 db.default.maxConnectionsPerPartition=5 db.default.minConnectionsPerPartition=5 

Then I used the following combination when using it:

 play clean play compile play eclipsify play ~run 

Alternatively, you can enter play dependencies after that to see if it is loaded correctly.

+6
source

All Articles