2013-03-08 5 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) 값을 수신하고이 열이 약간 다른 시간을 업데이트 할 수 있습니다로 다른 컬럼이 널 (null)로 업데이트 안 내 데이터베이스 테이블을 업데이트 할. 하지만, 그것은 어떤 쿼리 문자열이 아니라 빈 페이지를 표시하고 있습니다, 어떻게 내가 그 쿼리 문자열을 표시 얻을 알려 주시기 바랍니다. 난 당신의 코드를 이해하려고하면

감사

+0

질문을하고 자세한 내용을 보려면 faq http://stackoverflow.com/faq를 읽으십시오. –

답변

0

, 당신은 삼가지 경우

사례 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

미안하지만, 당신을 얻지 못했어요. 조금 맑게 해주시겠습니까? –

+1

당신이 얻지 못한 것은 무엇입니까? – PCoder

+0

"가능한 모든 경로를 따라 가지 않았습니다!" –

관련 문제