配置:
application.conf:
db.default.driver=com.mysql.jdbc.Driver
db.default.url="mysql://root:root@192.168.101.165:3306/bigdata?characterEncoding=UTF-8"
//db.default.username="root"
//db.default.password="root"
mysql://[用户名]:[密码]@[数据库地址]:[端口号]/[数据库名]
build.sbt:
libraryDependencies ++= Seq(javaJdbc,
"mysql" % "mysql-connector-java" % "5.1.18"
使用:
DataSource ds = DB.getDataSource();
boolean f = false;
try {
String sql = "select * from user where email='"+ req.getEmail() +"' and password='"+ req.getPwd() +"'";
java.sql.Connection con = ds.getConnection();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(sql);
while(rs.next()){
return ok("true");
}
// f = con.createStatement().execute("insert into user("
// + "name,password,email)Values"
// + "('test','test','test@test.com')"
// );
} catch (SQLException e) {
play.Logger.error(e.getMessage());
}