当前位置: 代码迷 >> Java Web开发 >> 请各位帮忙看下,不盛感激~
  详细解决方案

请各位帮忙看下,不盛感激~

热度:108   发布时间:2016-04-17 14:15:05.0
请各位大虾帮忙看下,不盛感激~!
我的程序有一段插入操作,在执行完毕后一又再次执行一次,不知道是不是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   {
  相关解决方案