+ -
当前位置:首页 → 问答吧 → JSP传值捞SQL语法有误??

JSP传值捞SQL语法有误??

时间:2011-11-25

来源:互联网

各位大大
请教一个问题,我想藉由修改栏位后将值塞入DB,但执行时却跑出java.lang.NullPointerException的错误,看SQL好像没什么问题,可以请各位协助看看吗~

程式码在此
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
form name="form1" method="post" action="../modifySrcList">
        <table width="100%" height="50" border="2" cellpadding="0" cellspacing="0">   <tr class="sidebarFooter">                 <td width="28%" height="50" class="sidebarFooter"><div align="center">通路别代码</div></td>     <td width="14%" height="50" class="sidebarFooter"><div align="center">区处别代码</div></td>
            <td width="14%" height="50" class="sidebarFooter"><div align="center">区处别名称</div></td>
             <td width="14%" height="50" class="sidebarFooter"><div align="center">通路别名称</div></td>
             <td width="15%" height="50" class="sidebarFooter"><div align="center">区处别别名</div></td>
             <td width="15%" height="50" class="sidebarFooter"><div align="center">权限角色名称</div></td>                         
           </tr>
          <tr bgcolor="#D1DAE9">
            <td width="28%" height="30"><div align="center"><%=request.getParameter("channel_type")%></div></td>
            <td width="14%" height="30"><div align="center"><input name="src_id" type="text" size="14" value="<%=request.getParameter("src_id")%>"></div></td>
            <td width="14%" height="30"><div align="center"><% request.setCharacterEncoding("big5"); %><%=request.getParameter("src_desc")%></div></td>
            <td width="14%" height="30"><div align="center"><% request.setCharacterEncoding("big5"); %><%=request.getParameter("channel_desc")%></div></td>
            <td width="15%" height="30"><div align="center"><input name="eng_name" type="text" size="14" value="<%=request.getParameter("eng_name")%>"></div></td>
            <td width="15%" height="30"><div align="center"><input name="role_name" type="text" size="14" value="<%=request.getParameter("role_id")%>"></div></td>
          </tr>          
        </table>
        <tr><td><div align="right">
          <input type="submit" name="Submit1" value=" 确认修改 " onClick="MM_popupMsg('修改完成!!')">
          <%
                  session.setAttribute("src_id",request.getParameter("src_id"));
               session.setAttribute("eng_name",request.getParameter("eng_name")); session.setAttribute("role_id",request.getParameter("role_id"));
          %>
        </div></td></tr>
      </form>


JSP背后的JAVA程式
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package tw.com.vibo.www.servlet;
import java.io.*;
 
import java.sql.Connection;
 
import java.sql.PreparedStatement;
 
import java.sql.SQLException;
 
import javax.servlet.ServletException;
 
import javax.servlet.http.HttpServlet;
 
import javax.servlet.http.HttpServletRequest;
 
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
//import oracle.jdbc.driver.OracleTypes;
 
import tw.com.vibo.www.singleton.connectionDB;
/** * @author Laurenceho20111125 * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */
 
public class modifySrcList extends HttpServlet { public String channel_type; public String src_id; public String src_desc; public String channel_desc; public String eng_name; public String role_id;
 
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Connection conn = connectionDB.getInstance().getConnection(); String qs; String sqlErrCheck = ""; PreparedStatement ps = null; try { request.setCharacterEncoding("big5"); //session为取得修改前的资讯 HttpSession session = request.getSession(); this.channel_type = session.getAttribute("channel_type").toString(); this.src_desc = session.getAttribute("src_desc").toString(); this.channel_desc = session.getAttribute("channel_desc").toString();
  conn.setAutoCommit(false); //不要自动commit
 
//---------------------------------------------------------4. 修改src_tab变更的资料---------------------------------------------------------------------  qs = "update src_tab st " + "set st.src_id = " + ((request.getParameter("src_id").length()!=0) ? " and st.src_id = "+request.getParameter("src_id") : "" ) + " ,st.eng_name = "+ ((request.getParameter("eng_name").length()!=0) ? " and st.eng_name = "+request.getParameter("eng_name") : "" ) + "where st.channel_type = '"+this.channel_type+"' "+ "and st.src_desc = '"+this.src_desc+"'" + "and st.channel_desc = '"+this.channel_desc+"'"; sqlErrCheck = qs; ps = conn.prepareStatement(qs); ps.executeUpdate();
  conn.commit(); if(ps!=null) ps.close(); conn.close();
  response.sendRedirect(response.encodeURL("import/viboSrcQuery.jsp"));
 
     } catch (SQLException e) { System.out.print(" sql exception : "+sqlErrCheck);
      e.printStackTrace();
     } catch (IOException e) {
      e.printStackTrace();
     } finally{ try{ if(ps!=null) ps.close(); if(conn!=null) conn.close(); } catch(Exception e){ e.printStackTrace(); } }
  }
}

错误讯息,初步看看似是SQL问题,但又找不出SQL哪里不对,还请协助看看~~

作者: supper03   发布时间: 2011-11-25

你的SQL组完
用println(qs);出来看看有没有接到你要值

作者: pclevin   发布时间: 2011-11-25