Play+jdbc操作数据库快速上手

2017-01-05 20:06:19来源:CSDN作者:oMrApollo人点击

配置:

application.conf:db.default.driver=com.mysql.jdbc.Driverdb.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());        }

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台