请各位大虾帮忙看下,不盛感激~!
我的程序有一段插入操作,在执行完毕后一又再次执行一次,不知道是不是BUG,应F6调式模式走,就是运行两次程序,执行了两次插入操作!!!小弟实在搞不明白,望指点!
<%@ page language= "java " pageEncoding= "gb2312 "%>
<%@ page import= "exe.* "%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
<html>
<head>
<title> MyJsp.jsp </title>
</head>
<body>
<%
dealString deal=new dealString();
writeFrom frm =new writeFrom();
write wt=new write();
String title=String.valueOf(request.getParameter( "title "));
String a=String.valueOf(request.getParameter( "a "));
String b=String.valueOf(request.getParameter( "b "));
String c=String.valueOf(request.getParameter( "c "));
String d=String.valueOf(request.getParameter( "d "));
String hit=request.getParameter( "hit ");
String timer=String.valueOf(deal.getDateTime());
frm.setTITLE(title.trim());
frm.setTITLE_A(a.trim());
frm.setTITLE_B(b.trim());
frm.setTITLE_C(c.trim());
frm.setTITLE_D(d.trim());
frm.setID_RUBRIC(timer);
frm.setDA(hit);
wt.add(frm);
out.print( "插入成功 ");
%>
</body>
</html>
public class write {
PreparedStatement stmt = null;
public int add(writeFrom frm)
{
String sql= "insert into exam_write (ID_RUBRIC,TITLE,TITLE_A,TITLE_B,TITLE_C,TITLE_D,DA) values(?,?,?,?,?,?,?) ";
int result = 2 ;
Connection conn = ConnectionFactory.newInstance().getConnection();
if(conn == null){
result=2;
return result;
}
try
{
stmt = conn.prepareStatement(sql);
stmt.setString(1, frm.getID_RUBRIC());
stmt.setString(2, frm.getTITLE());
stmt.setString(3, frm.getTITLE_A());
stmt.setString(4, frm.getTITLE_B());
stmt.setString(5, frm.getTITLE_C());
stmt.setString(6, frm.getTITLE_D());
stmt.setString(7, frm.getDA());
result=stmt.executeUpdate();
}catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
finally
{
try {
stmt.close();
conn.close();
} catch (SQLException ex1) {
}
}
return result;
}
}
[解决办法]
这个文件看起来没有问题啊!