0

如何编写 sql 查询以使用 jdbc 在 2 列上创建具有唯一约束的表:我尝试此代码并给我“SQLException:无效的创建语句!”:

 Connection conn = ConnectDB.getConnection();
    Statement stmt = null;
    try {
            String sql = "CREATE TABLE TBL_fonts" +
                    + "(char_id int not NULL, "
                    + "FW VARCHAR(255), "
                    + "code VARCHAR(255), "
                    + "character VARCHAR(255), "
                    + "CONSTRAINT fontConst UNIQUE(FW,code), "
                    + "PRIMARY KEY (char_id))";
            stmt = conn.createStatement();
            stmt.executeUpdate(sql);
        conn.commit();
    } catch (SQLException ex) {
        ex.printStackTrace();
    }
4

1 回答 1

3

此问题已在 UCanAccess 2.0.6.2 中修复。编码

String sql = 
        "CREATE TABLE TBL_fonts ("
        + "char_id int not NULL, "
        + "FW VARCHAR(255), "
        + "code VARCHAR(255), "
        + "character VARCHAR(255), "
        + "CONSTRAINT fontConst UNIQUE(FW,code), "
        + "PRIMARY KEY (char_id)"
        + ")";
Statement stmt = conn.createStatement();
stmt.executeUpdate(sql);

现在按预期工作。

于 2014-06-01T14:48:11.147 回答