如何使用UCanAccess在两列上创建具有唯一约束的TABLE?

时间:2014-05-28 07:20:30

标签: java ms-access jdbc ucanaccess

如何使用jdbc编写sql查询以在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();
    }

1 个答案:

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

现在按预期工作。