有没有办法在执行前记录Anorm语句。目前我正在通过JDBC驱动程序技巧记录语句:
application.conf:
db.default.driver="com.mysql.jdbc.Driver"
db.default.url="jdbc:mysql://someDBServer/db?useUnicode=true&characterEncoding=utf8&autoReconnect=true&logger=com.mysql.jdbc.log.Slf4JLogger&profileSQL=true"
db.default.logStatements=true
但是我想在执行之前记录语句,以便进行调试和记录。例如,我的sql语法有错误,我使用Hickary CP(2.5.x Playframework)
日志输出无效:
2017-01-23 16:37:01 application-akka.actor.default-dispatcher-3 [INFO ] controllers.AppController - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:400)
at com.mysql.jdbc.Util.getInstance(Util.java:383)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:980)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3847)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3783)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2447)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2594)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1901)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2113)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2049)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2034)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
at anorm.Sql$$anonfun$executeUpdate$1.apply(Anorm.scala:163)
at anorm.Sql$$anonfun$executeUpdate$1.apply(Anorm.scala:163)
Println也没有帮助:
db.withConnection { implicit c =>
def sql = SQL("delete from USER where (username = {username} or username = {org_jed }) and id = {id}").on(
'username -> user.username,
'org_jed -> user.org_jed,
'id -> some.id
)
println("Statement: " + sql.preparedStatement(c))
sql.executeUpdate()
}