我有以下代码,当它在UPDATED
的记录上执行时,记录实际上最终从数据库表中DELETED
。这是一个Oracle数据库。很奇怪。到目前为止,我无法从数据库服务器中提取任何可能解释较低级别发生的情况的日志信息。我包含的The System.out.println
语句显示了我在执行时期望的输出,但是,当我通过java应用程序本身搜索记录,然后通过SQL Developer工具搜索记录时 - 查看表格本身,实际数据消失了。这是我的java代码。感谢,任何关于更新如何以及为何执行删除而不仅仅是更新的想法,想法或答案都表示赞赏。如果您还有其他任何我没有正确提供的东西,请告诉我,谢谢。
Class.forName("oracle.jdbc.driver.OracleDriver");
.
.
.
if(PBupdate.equals("updaterecords")) {
try {
ArrayList resultsArray = (ArrayList) session.getAttribute("searchresults");
int pos = 0;
String ID = "";
System.out.println("updatestaff : pos = " + pos + " resultsArray.size() = " + resultsArray.size());
while (pos < resultsArray.size()) {
System.out.println("updatestaff : pos = " + pos);
System.out.println("updatestaff : resultsArray.get(pos + 1) = " + resultsArray.get(pos + 1));
ID = "" + resultsArray.get(pos + 0) + "";
Last_Name = "" + resultsArray.get(pos + 1) + "";
First_Name = "" + resultsArray.get(pos + 2) + "";
Middle = "" + resultsArray.get(pos + 3) + "";
Phone = "" + resultsArray.get(pos + 4) + "";
Dept_Code = "" + resultsArray.get(pos + 5) + "";
Email = "" + resultsArray.get(pos + 6) + "";
Title = "" + resultsArray.get(pos + 7) + "";
Fax_Code = "" + resultsArray.get(pos + 8) + "";
Loc_Code = "" + resultsArray.get(pos + 9) + "";
System.out.println("updatestaff : ID = " + ID);
System.out.println("updatestaff : Last_Name = " + Last_Name);
System.out.println("updatestaff : First_Name = " + First_Name);
System.out.println("updatestaff : Middle = " + Middle);
System.out.println("updatestaff : Phone = " + Phone);
System.out.println("updatestaff : Dept_Code = " + Dept_Code);
System.out.println("updatestaff : Email = " + Email);
System.out.println("updatestaff : Title = " + Title);
System.out.println("updatestaff : Fax_Code = " + Fax_Code);
System.out.println("updatestaff : Loc_Code = " + Loc_Code);
stmt = conn.prepareStatement("UPDATE STAFFDIR SET Last_Name = ?, First_Name = ?, Middle = ?, Phone = ?, Dept_Code = ?, Email = ?, Title = ?, Fax_Code = ?, Loc_Code = ? WHERE ID = ?");
stmt.setString(1, Last_Name);
stmt.setString(2, First_Name);
stmt.setString(3, Middle);
stmt.setString(4, Phone);
Integer DC = Integer.valueOf(Dept_Code);
System.out.println("updatestaff: Dept_Code = " + Dept_Code);
stmt.setInt(5, DC);
stmt.setString(6, Email);
stmt.setString(7, Title);
if ((Fax_Code == null) || (Fax_Code.equals("")) || (Fax_Code.equals("null"))) {
Fax_Code = "999";
}
System.out.println("updatestaff: Fax_Code = " + Fax_Code);
Integer FC = Integer.valueOf(Fax_Code);
stmt.setInt(8, FC);
Integer LC = Integer.valueOf(Loc_Code);
System.out.println("updatestaff: Loc_Code = " + Loc_Code);
stmt.setInt(9, LC);
stmt.setString(10, ID);
int rc = stmt.executeUpdate();
System.out.println("update : rc = " + rc);
SQLWarning warning = conn.getWarnings();
while (warning != null)
{
System.out.println(warning.getMessage());
warning = warning.getNextWarning();
}
pos = pos + 14;
}
response.sendRedirect(response.encodeRedirectURL("/phonebk/updatestaff.jsp"));
} // End of try