如何使用 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();
}
最佳答案
此问题已在 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);
现在可以按预期工作。
关于java - 如何使用 UCanAccess 创建对两列具有唯一约束的表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23905122/