我正在编写一个Java例程以在表中添加行。我已经使用了try catch子句。 当有重复的条目时,代码将引发-803异常并终止程序。
我需要的是跳过重复条目并添加新条目的程序。
代码:
try{
conn = DriverManager.getConnection(db2url);
con = DriverManager.getConnection(jdbcurl,user,password);
Statement statehits = conn.createStatement();
Statement state = con.createStatement();
ResultSet srt = state.executeQuery("select * from dbo.v_IDM");
while(srt.next())
{
statehits.executeUpdate("insert into maximo.hits (HITSID,HASLD,EMPLOYEEID,LOGON_NAME,DESIGNATION,DEPARTMENT,MANAGERNUMBER,MANAGERNAME,LOCATION) values ("+srt.getString("EMPLOYEE_NUMBER")+", 0 ,'"+ srt.getString("EMPLOYEE_NUMBER")+"','"+ srt.getString("LOGON_NAME")+"','"+ srt.getString("DESIGNATION")+"','"+srt.getString("DEPARTMENT")+"','"+ srt.getString("MANAGERNUMBER")+"','"+ srt.getString("MANAGERNAME")+"','"+ srt.getString("LOCATION")+"')");
count++;
}
System.out.print(count);
}catch(SQLException e){
e.printStackTrace();
}