我刚刚开始使用JOOQ。我在Eclipse中使用Google App Engine运行它。代码生成很顺利,但是当我尝试这个create.select().from(CLIENT_MASTER).fetch();
时,我得到以下错误。
org.jooq.exception.DataAccessException: SQL [select `admin_kpi`.`client_master`.`client_id`, `admin_kpi`.`client_master`.`first_name`, `admin_kpi`.`client_master`.`last_name`, `admin_kpi`.
ASASD2FDFDWhat is your name? abcdedsad0PinnacleA3Z2UiBLQsCgSDh
210.89.56.250active2013-11-28 14:52:48enableyadmin_pinnacle_mr123456789123122
2014-12-30
0000-00-00310' can not be represented as java.sql.Date
at org.jooq.impl.Tools.translate(Tools.java:1941)
at org.jooq.impl.DefaultExecuteContext.sqlException(DefaultExecuteContext.java:659)
at org.jooq.impl.CursorImpl$CursorIterator.fetchOne(CursorImpl.java:1556)
at org.jooq.impl.CursorImpl$CursorIterator.hasNext(CursorImpl.java:1507)
at org.jooq.impl.CursorImpl.fetch(CursorImpl.java:329)
at org.jooq.impl.CursorImpl.fetch(CursorImpl.java:282)
at org.jooq.impl.AbstractResultQuery.execute(AbstractResultQuery.java:282)
at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:348)
at org.jooq.impl.AbstractResultQuery.fetch(AbstractResultQuery.java:312)
at org.jooq.impl.SelectImpl.fetch(SelectImpl.java:2705)
at com.cbcdashboard.live.DailyReportServlet.doGet(DailyReportServlet.java:33)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:128)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:48)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366)
at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349)
at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:95)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:508)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.sql.SQLException: Value '1MrPinnacleMRc-4 yashonandan parkamericaVadodara5390016 1323131232mr
ASASD2FDFDWhat is your name? abcdedsad0PinnacleA3Z2UiBLQsCgSDh
210.89.56.250active2013-11-28 14:52:48enableyadmin_pinnacle_mr123456789123122
2014-12-30
0000-00-00310' can not be represented as java.sql.Date
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1056)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
at com.mysql.jdbc.ResultSetRow.getDateFast(ResultSetRow.java:134)
at com.mysql.jdbc.BufferRow.getDateFast(BufferRow.java:698)
at com.mysql.jdbc.ResultSetImpl.getDate(ResultSetImpl.java:2108)
at com.mysql.jdbc.ResultSetImpl.getDate(ResultSetImpl.java:2060)
at org.jooq.impl.CursorImpl$CursorResultSet.getDate(CursorImpl.java:709)
at org.jooq.impl.DefaultBinding.getDate(DefaultBinding.java:1972)
at org.jooq.impl.DefaultBinding.get(DefaultBinding.java:1349)
at org.jooq.impl.CursorImpl$CursorIterator$CursorRecordInitialiser.setValue(CursorImpl.java:1640)
at org.jooq.impl.CursorImpl$CursorIterator$CursorRecordInitialiser.operate(CursorImpl.java:1611)
at org.jooq.impl.CursorImpl$CursorIterator$CursorRecordInitialiser.operate(CursorImpl.java:1576)
at org.jooq.impl.RecordDelegate.operate(RecordDelegate.java:128)
at org.jooq.impl.CursorImpl$CursorIterator.fetchOne(CursorImpl.java:1540)
... 45 more
看起来它正在尝试获取所有字段返回的数据并将整个字符串转换为java.sql.Date?有谁看到我做错了什么?
代码
try (Connection connection = getConnection()) {
DSLContext create = DSL.using(connection, SQLDialect.MYSQL);
Result<Record> results = create.select().from(CLIENT_MASTER).fetch();
resp.setContentType("text/html");
PrintWriter writer = resp.getWriter();
for (Record result : results) {
writer.println(result.getValue(CLIENT_MASTER.COMPANY));
}
} catch (SQLException | InstantiationException | IllegalAccessException | ClassNotFoundException e) {
logger.log(Level.SEVERE, "Failed to connect to mysql", e);
}
表
CREATE TABLE `client_master` (
`client_id` int(11) NOT NULL AUTO_INCREMENT,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
`company` varchar(255) NOT NULL,
`address1` varchar(255) NOT NULL,
`address2` varchar(255) NOT NULL,
`city` varchar(255) NOT NULL,
`state` varchar(255) NOT NULL,
`country` varchar(255) NOT NULL,
`zipcode` varchar(50) NOT NULL,
`phone_number` varchar(50) NOT NULL,
`group_member` varchar(255) NOT NULL,
`user_name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`accountno` varchar(255) NOT NULL,
`security_que` varchar(255) NOT NULL,
`security_ans` varchar(255) NOT NULL,
`payment` varchar(255) NOT NULL,
`store` text,
`inventory` enum('xx','xx') NOT NULL DEFAULT 'xx',
`activation_code` varchar(255) NOT NULL,
`ip_address` text NOT NULL,
`status` enum('active','inactive') NOT NULL,
`register_date` datetime NOT NULL,
`enable_desable` enum('enable','desable') NOT NULL,
`is_delete` varchar(50) NOT NULL,
`data_base` varchar(255) NOT NULL,
`secret_id` varchar(255) NOT NULL,
`licence_id` varchar(255) NOT NULL,
`tokon_no` varchar(255) NOT NULL,
`exp_date` date NOT NULL,
`c_token` varchar(255) NOT NULL,
`sub_type` varchar(20) NOT NULL,
`pac_exp_date` date NOT NULL,
`pac_amount` varchar(20) NOT NULL,
`act_store` varchar(255) NOT NULL,
`def_store` varchar(255) NOT NULL,
`is_full_sync` enum('0','1','2','3') NOT NULL DEFAULT '0',
`eng_flag` enum('0','1') NOT NULL DEFAULT '0',
`upg_flag` enum('0','1') NOT NULL DEFAULT '0',
PRIMARY KEY (`client_id`)
) ENGINE=InnoDB AUTO_INCREMENT=418 DEFAULT CHARSET=latin1;
用于创建JOOQ类的XML文件:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.8.0.xsd">
<!-- Configure the database connection here -->
<jdbc>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://xx.xx.xx.xx:3306/admin_kpi</url>
<user>xx</user>
<password>xx</password>
</jdbc>
<generator>
<name>org.jooq.util.JavaGenerator</name>
<database>
<name>org.jooq.util.mysql.MySQLDatabase</name>
<inputSchema>admin_kpi</inputSchema>
<includes>.*</includes>
<excludes></excludes>
</database>
<target>
<packageName>xxxxx</packageName>
<directory>xxx</directory>
</target>
</generator>
</configuration>
答案 0 :(得分:0)
我遇到了同样的问题,我追踪到这种行为的原因是0000-00-00
作为某个日期列和conn.getZeroDateTimeBehavior() == ConnectionPropertiesImpl.ZERO_DATETIME_BEHAVIOR_EXCEPTION
的值。