Ucanaccess错误-意外的令牌


//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);

这一直给我以下错误:net.ucanaccess.jdbc.UcanaccessSQLException:意外token: 2"

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

我能够在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)";

相关内容

  • 没有找到相关文章

最新更新