Issue Connecting to Postgres

347 views
Skip to first unread message

Dan Sadowski

unread,
May 26, 2016, 1:19:00 AM5/26/16
to play-framework
I'm having an issue getting connected to Postgresql. I'm getting the following exception:

play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [db]]

at play.api.Configuration$.configError(Configuration.scala:154)

a...

Caused by: play.api.Configuration$$anon$1: Configuration error[either dataSource or dataSourceClassName is required]

...

Caused by: java.lang.IllegalArgumentException: either dataSource or dataSourceClassName is required

at com.zaxxer.hikari.HikariConfig.validate(HikariConfig.java:785)

at play.api.db.HikariCPConfig.toHikariConfig(HikariCPModule.scala:140)

...

at play.api.db.DefaultDatabase.getConnection(Databases.scala:143)



My build.sbt looks like the following:

name := """test"""

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayJava)

scalaVersion := "2.11.7"

libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs
)

// http://mvnrepository.com/artifact/org.postgresql/postgresql
libraryDependencies += "org.postgresql" % "postgresql" % "9.4.1208.jre7"
//fork in run := true


My db config looks like this:

db {
  # You can declare as many datasources as you want.
# By convention, the default datasource is named `default`

# https://www.playframework.com/documentation/latest/Developing-with-the-H2-Database
#db.default.
#
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://localhost/test" #the port is optional
#db.default.hikaricp.dataSourceClassName=org.postgresql.ds.PGPoolingDataSource
db.default.username="play"
db.default.password="play"

# You can turn on SQL logging for any datasource
# https://www.playframework.com/documentation/latest/Highlights25#Logging-SQL-statements
#default.logSql=true
}


I've tried a number of different JDBC drivers and db properties. Any ideas on how to resolve this would be really appreciated. 
I can connect to the database and run sql out of a java client
  
public static void main(String[] args) throws SQLException{
System.out.println("Hello World!");

String url = "jdbc:postgresql://localhost/test";
Properties props = new Properties();
props.setProperty("user","play");
props.setProperty("password","play");
props.setProperty("ssl","false");
Connection conn = DriverManager.getConnection(url, props);
Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery("select current_user");
rs.next();
System.out.print(rs.getString(1));
}

Thanks,
Dan

Dan Sadowski

unread,
May 26, 2016, 1:39:58 AM5/26/16
to play-framework
I resolved it... needed to remove the db. prefix since the properties are inside of the db{} block.
Reply all
Reply to author
Forward
0 new messages