Ucanaccess 错误 - 意外令牌

Ucanaccess error - unexpected token

//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.ucanaccess.jdbc.UcanaccessSQLException:意外标记:2 net.ucanaccess.jdbc.UcanaccessStatement.execute(UcanaccessStatement.java:109)"

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

我能够使用以下代码在 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)";