我有一个我正在尝试更新的应用程序,因为它使用的是jdbc驱动程序(sun.jdbc.odbc.jdbcodbcdriver),现在正在使用Ucanaccess。目前应用程序正确访问数据库,但未能对Access数据库进行更改,我认为可能是由于日期格式或时间格式。
相关,当日期格式从#01/02/08#更改为#01/02/2008#时,从表中删除行的功能成功运行。
这是queryString的输出:
Insert into
follow(
f_c_id,
f_date,
f_time_begin,
f_time_end,
f_flag_begin_in,
f_flag_end_in,
start_map_number,
end_map_number,
b_observer,
map_observer,
start_Map_Time,
end_Map_Time,
f_duration) values (
'ert',
#11/11/1989#,
#11:11#,
#12:12#,
-1,
-1,
1,
21,
'sf',
'sdg',
#12:12#,
#13:13#,
61)
这是一个功能片段:
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
conn = DriverManager.getConnection("jdbc:ucanaccess://C:/Data/Example.mdb", "", "");
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
queryString = "Insert into following (f_c_id, f_date, f_time_begin, f_time_end, " +
"f_flag_begin_in, f_flag_end_in, start_map_number, end_map_number, b_observer," +
"map_observer, start_Map_Time, end_Map_Time,f_duration)" +
" values ('" + IDText.getText() +
"'," + "#" + focalDate + "#" +
"," + "#" + focalTimeStart + "#" +
"," + "#" + focalTimeEnd + "#" +
"," + startNestCheck + "," + endNestCheck +
"," + startMapNumText.getText() +
"," + endMapNumText.getText() +
",'" + bObserverText.getText() +
"','" + mapObserverText.getText() +
"'," + "#" + startMapTime + "#" +
"," + "#" + endMapTime + "#" +
"," + fDuration +
")";
System.out.print(queryString);
stmt.executeUpdate(queryString);
conn.close();
} catch (Exception e) {
if (!(e.getMessage().equalsIgnoreCase("No ResultSet was produced"))) {
e.printStackTrace();
System.exit(1);
}
}
和stacktrace:
net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::4.0.2 unknown token:
at net.ucanaccess.jdbc.UcanaccessStatement.executeUpdate(UcanaccessStatement.java:221)
at Test.clearTable(Test.java:2335)
at Test.genericButtonActionPerformed(Test.java:2266)
at Test.access$1200(Test.java:20)
at Test$14.actionPerformed(Test.java:801)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.sql.SQLSyntaxErrorException: unknown token:
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.executeUpdate(Unknown Source)
at net.ucanaccess.jdbc.ExecuteUpdate.executeWrapped(ExecuteUpdate.java:67)
at net.ucanaccess.jdbc.AbstractExecute.executeBase(AbstractExecute.java:208)
at net.ucanaccess.jdbc.ExecuteUpdate.execute(ExecuteUpdate.java:50)
at net.ucanaccess.jdbc.UcanaccessStatement.executeUpdate(UcanaccessStatement.java:219)
... 40 more
Caused by: org.hsqldb.HsqlException: unknown token:
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.ParserBase.read(Unknown Source)
at org.hsqldb.ParserDQL.XreadPredicateRightPart(Unknown Source)
at org.hsqldb.ParserDQL.XreadBooleanPrimaryOrNull(Unknown Source)
at org.hsqldb.ParserDQL.XreadBooleanTestOrNull(Unknown Source)
at org.hsqldb.ParserDQL.XreadBooleanFactorOrNull(Unknown Source)
at org.hsqldb.ParserDQL.XreadBooleanTermOrNull(Unknown Source)
at org.hsqldb.ParserDQL.XreadBooleanValueExpression(Unknown Source)
at org.hsqldb.ParserDML.compileDeleteStatement(Unknown Source)
at org.hsqldb.ParserCommand.compilePart(Unknown Source)
at org.hsqldb.ParserCommand.compileStatements(Unknown Source)
at org.hsqldb.Session.executeDirectStatement(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
... 46 more
Process finished with exit code 1
答案 0 :(得分:1)
UCanAccess(目前)不会识别仅包含小时和分钟的仅限时间的文字。但是,它确实识别包含小时,分钟和秒的文字。
所以这会失败......
UCanAccess>INSERT INTO Table4 (dtmField) VALUES (#11:11#);
UCanAccess>UCAExc:::4.0.2 unknown token:
......但这有效:
UCanAccess>INSERT INTO Table4 (dtmField) VALUES (#11:11:00#);
UCanAccess>1 row(s) affected
同样,它无法识别具有两位数年份的日期文字,因此失败...
UCanAccess>INSERT INTO Table4 (dtmField) VALUES (#12/25/17#);
UCanAccess>UCAExc:::4.0.2 unknown token:
......但这成功了:
UCanAccess>INSERT INTO Table4 (dtmField) VALUES (#12/25/2017#);
UCanAccess>1 row(s) affected