2013-03-08 43 views
0

我的jsp如下。更新基于jsp输入的数据库

<%@page contentType="text/html" pageEncoding="UTF-8"%> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> 
    <html> 
     <head> 
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
      <title>JSP Page</title> 
     </head> 
     <body> 
      <form name="a" action="abc.jsp" method="post"> 
      <input type="abc" id="abc" name="abc"> 
      <input type="def" id="def" name="def"></form> 
     </body> 
    </html> 

and the jsp that it is redirected is as below 

     <%@include file="DBCon.jsp" %> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title>JSP Page</title> 
    </head> 
    <body> 
     <%try 
      { 
      int s; 
     String a=request.getParameter("a"); 
     String b=request.getParameter("b"); 
     String c=request.getParameter("Ship_ID"); 
     ps=con.prepareStatement("select TSI_QUERY,TSI_R,TSI_C,SI_QUERY,SI_R, SI_C from topical"); 
     rs=ps.executeQuery(); 
     if(rs.next()){ 
     if(rs.getString("TSI_Query")==null && rs.getString("SI_Query")!=null) 
     { 
      String p="update topical set SI_Query='"+a+"', SI_R='x',SI_C='y' where Job_ID='"+c+"'"; 
      System.out.print(p); 
      /*ps1=con.prepareStatement("update topical set TSI_Query=?, TSI_R=?,TSI_C=?"); 
      ps1.setString(1, a); 
      ps1.setString(2, "x"); 
      ps1.setString(3, "y"); 
      s=ps1.executeUpdate(); 
      if(s!=0){ 
       String redirectURL= "a.jsp"; 
       response.sendRedirect(redirectURL); 
      }*/ 
     } 
       else if(rs.getString("SI_Query")==null && rs.getString("TSI_Query")!=null) 
     { 
      String p="update topical set SI_Query='"+b+"', SI_R='x',SI_C='y'where Job_ID='"+c+"'"; 
      System.out.print(p); 

      /*ps1=con.prepareStatement("update topical set SI_Query=?, SI_R=?,SI_C=?"); 
      ps1.setString(1, b); 
      ps1.setString(2, "x"); 
      ps1.setString(3, "y"); 
      s=ps1.executeUpdate(); 
      if(s!=0){ 
      String redirectURL= "a.jsp"; 
      response.sendRedirect(redirectURL);}*/ 
     } 
       else if(rs.getString("SI_Query")==null && rs.getString("TSI_Query")==null){ 
        if(a==null && b!=null) 
              { 
       String p="update topical set TSI_Query='"+a+"', TSI_R='x',TSI_C='y'where Job_ID='"+c+"'"; 
      /* ps1=con.prepareStatement("update topical set TSI_Query=?, TSI_R=?,TSI_C=?"); 
      ps1.setString(1, a); 
      ps1.setString(2, "x"); 
      ps1.setString(3, "y"); 
      s=ps1.executeUpdate(); 
      if(s!=0){ 
       String redirectURL= "a.jsp"; 
       response.sendRedirect(redirectURL); 
           } 
       */  } 
       else if(b==null && a!=null){ 
      String p="update topical set SI_Query='"+b+"', SI_R='x',SI_C='y'where Job_ID='"+c+"'"; 
      System.out.print(p); 
        /* 
      ps1=con.prepareStatement("update topical set SI_Query=?, SI_R=?,SI_C=?"); 
      ps1.setString(1, b); 
      ps1.setString(2, "x"); 
      ps1.setString(3, "y"); 
      s=ps1.executeUpdate(); 
      if(s!=0){ 
       String redirectURL= "a.jsp"; 
       response.sendRedirect(redirectURL); 
           }*/ 
       } 
       } 
       } 

     } 
     catch(Exception e) 
     { 
     out.println(e); 
     } 
     %> 
    </body> 
</html> 

在这里,我想收到的非空值和其他列不应该被更新null作为此列可能会更新一些其他的时间来更新我的数据库表。但是,它显示的是一个空白页面,而不是任何查询字符串,请让我知道如何获取显示的查询字符串。

感谢

+0

阅读常见问题解答http://stackoverflow.com/faq关于如何提出问题并返回更多详细信息。 – 2013-03-08 13:05:05

回答

0

如果我试图理解你的代码,你似乎有3案件

案例1

TSI_Query == null && SI_Query != null 
//print something 

案例2

SI_Query ==null && TSI_Query != null 
//print something 

案例3

SI_Query ==null && TSI_Query == null 
    // check values of a and b, and print only if b==null && a!=null 

所以你有效的,不是遵循所有可能的路径!难怪你没有任何产出。请注意,你也可能是其他问题。

+0

对不起,我没有得到你,你可以请清楚一点 – 2013-03-08 13:18:48

+1

你没有得到什么? – PCoder 2013-03-08 13:21:28

+0

“没有遵循所有可能的路径!” – 2013-03-08 13:33:09