
java.sql.SQLIntegrityConstraintViolationException:是什么错误
Thestatementwasabortedbecauseitwouldhavecausedaduplicatekeyvalueinauniqueorprimarykey...
The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL120227211351350' defined on 'TB_TABS'.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
.......
部分代码:
public void storeTabs(int tabNum, String tabName){
if(tabName == null || tabName.equals(""))
return;
if(!tabExist(tabName)){
try{
String sql = "insert into tb_tabs values(?,?,?)";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, tabNum);
ps.setString(2, tabName);
ps.setInt(3, tabNum +5);
ps.execute(); //提示错误在这个地方
ps.close();
}catch(SQLException e){
e.printStackTrace();
}
}
} 展开
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
.......
部分代码:
public void storeTabs(int tabNum, String tabName){
if(tabName == null || tabName.equals(""))
return;
if(!tabExist(tabName)){
try{
String sql = "insert into tb_tabs values(?,?,?)";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, tabNum);
ps.setString(2, tabName);
ps.setInt(3, tabNum +5);
ps.execute(); //提示错误在这个地方
ps.close();
}catch(SQLException e){
e.printStackTrace();
}
}
} 展开
展开全部
it would have caused a duplicate(重复) key value in a unique or primary key
说的是因为有一个唯一的键值重复了,可能是你插入了两条主键一样的数据,数据库里的主键是不能重复的
说的是因为有一个唯一的键值重复了,可能是你插入了两条主键一样的数据,数据库里的主键是不能重复的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询