我正在尝试将一个简单的查询插入到 Microsoft 数据库中,并且我正在使用 UCanAccess
Posted
技术标签:
【中文标题】我正在尝试将一个简单的查询插入到 Microsoft 数据库中,并且我正在使用 UCanAccess【英文标题】:I am trying to insert a simple query into a Microsoft database and i am using UCanAccess 【发布时间】:2021-09-30 11:55:30 【问题描述】:我的密码:
String databaseURL = "jdbc:ucanaccess://Orders.accdb";
try
Connection connection = DriverManager.getConnection(databaseURL);
System.out.println("Connected to MS Access database");
String sql = "INSERT INTO Orders (Order Date, Completion Date, Starting Date, Machine, Client, Job Name, Comment) VALUES"
+ "('9/30/2021', '9/30/2021', '9/30/2021', 'Okay', 'Okay', 'Okay', 'Yes you are Okay')";
Statement statement = connection.createStatement();
int rows = statement.executeUpdate(sql);
if (rows > 0 )
System.out.println("A new thing has been inserted.");
connection.close();
catch (SQLException ex)
Logger.getLogger(OrdersTestCode.class.getName()).log(Level.SEVERE, null, ex);
我的错误
2021-09-30T13:50:45.315+0200 SEVERE null
net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::5.0.1 user lacks privilege or object not found: ORDER
at net.ucanaccess.jdbc.UcanaccessStatement.executeUpdate(UcanaccessStatement.java:230)
at orderstestcode.OrdersTestCode.main(OrdersTestCode.java:29)
Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: ORDER
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:65)
at net.ucanaccess.jdbc.AbstractExecute.executeBase(AbstractExecute.java:264)
at net.ucanaccess.jdbc.ExecuteUpdate.execute(ExecuteUpdate.java:48)
at net.ucanaccess.jdbc.UcanaccessStatement.executeUpdate(UcanaccessStatement.java:228)
... 1 more
Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: ORDER
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.ParserDQL.readSimpleColumnName(Unknown Source)
at org.hsqldb.ParserDQL.readSimpleColumnNames(Unknown Source)
at org.hsqldb.ParserDML.compileInsertStatement(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)
... 7 more
我设置了一个断点,它在 int Rows 行崩溃。我确信这可能是我的 SQL 语句,但我可能错了。有人可以帮我找出问题所在吗?
【问题讨论】:
表存在吗? 【参考方案1】:尝试使用正确的 Access SQL 语法:
String sql = "INSERT INTO Orders ([Order Date], [Completion Date], [Starting Date], Machine, Client, [Job Name], Comment) VALUES "
+ "(#9/30/2021#, #9/30/2021#, #9/30/2021#, 'Okay', 'Okay', 'Okay', 'Yes you are Okay')";
【讨论】:
以上是关于我正在尝试将一个简单的查询插入到 Microsoft 数据库中,并且我正在使用 UCanAccess的主要内容,如果未能解决你的问题,请参考以下文章