gpt4 book ai didi

netbeans - Ucanaccess 错误 - 意外 token

转载 作者:行者123 更新时间:2023-12-02 01:34:05 26 4
gpt4 key购买 nike

//golfer and CourseName are strings initialised earlier 
String query = "INSERT INTO Temp (GolferID,CourseID,DatePlayed,1st,2nd,3rd,4th,5th,6th,7th,8th,9th,10th,11th,"
+ "12th,13th,14th,15th,16th,17th,18th)VALUES('"
+ golfer + "','" + CourseName + "',#1/1/2011#";

for(int j = 0; j <=17; j++)
{
query = query + "," + Scores[j];
}
query = query + ")";
System.out.println(query);
//INSERT INTO Temp(GolferID,CourseID,DatePlayed,1st,2nd,3rd,4th,5th,6th,7th,8th,9th,10th,11th,12th,13th,14th,15th,16th,17th,18th)VALUES('test','Blue Valley CC',#1/1/2011#,4,3,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)*/
\\this is what the string eventually looks like.

DBConnect db = new DBConnect();
db.InsertGame(query);

这是 DBConnect - InsertGame 中的相关代码...

connection = DriverManager.getConnection("jdbc:ucanaccess://Golf.accdb");
statement = connection.createStatement();//declared earlier
statement.execute(query);

这一直给我以下错误:严重:null net.ucanacess.jdbc.UcanaccessSQLException:意外 token :2 net.ucanacess.jdbc.UcanaccessStatement.execute(UcanaccessStatement.java:109)”

如果我将查询直接复制并粘贴到访问中,它会完美执行。我正在使用相同的方法插入数据库中的另一个表,它工作得很好,但是所有这些字段都是文本字段。我不太确定这是否有所作为。

最佳答案

我能够使用以下代码在 UCanAccess 3.0.0 下重现您的问题:

sql = 
"INSERT INTO Temp (GolferID,CourseID,DatePlayed,1st,2nd,3rd) " +
"VALUES ('test','Blue Valley CC',#1/1/2011#,4,3,5)";

UCanAccess 似乎对列名 2nd 感到困惑。当我将列名括在方括号中时,我能够成功执行该语句:

sql = 
"INSERT INTO Temp (GolferID,CourseID,DatePlayed,[1st],[2nd],[3rd]) " +
"VALUES ('test','Blue Valley CC',#1/1/2011#,4,3,5)";

关于netbeans - Ucanaccess 错误 - 意外 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32216035/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com