Ucanaccess错误 - 意外令牌

时间:2015-08-26 00:06:45

标签: netbeans 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);

这一直给我以下错误: SEVERE:null net.ucanaccess.jdbc.UcanaccessSQLException:意外令牌:2 net.ucanaccess.jdbc.UcanaccessStatement.execute(UcanaccessStatement.java:109)&#34;

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

1 个答案:

答案 0 :(得分: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)";