[英]How to CREATE TABLE with unique constraint on two columns using UCanAccess?
How to write sql query to create table with unique constraint on 2 columns using jdbc: I try this code and give me "SQLException: Invalid create statement!": 如何编写SQL查询以使用jdbc在2列上创建具有唯一约束的表:我尝试使用此代码,并给我“ SQLException:无效的create语句!”:
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();
}
This issue has been fixed in UCanAccess 2.0.6.2. 此问题已在UCanAccess 2.0.6.2中修复。 The code
编码
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);
now works as expected. 现在可以正常工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.