JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 新手區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 JSP傳值撈SQL語法有誤??
supper03





發文: 59
積分: 0
於 2011-11-25 18:37 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
各位大大
請教一個問題,我想藉由修改欄位後將值塞入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哪裡不對,還請協助看看~~


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
1039 JSP傳值撈SQL語法有誤?? supper03 5800 2011-11-25 18:37
936 Re:JSP傳值撈SQL語法有誤?? pclevin 188 2011-11-25 20:59
919 Re:JSP傳值撈SQL語法有誤?? supper03 16 2011-11-26 07:29
919 Re:JSP傳值撈SQL語法有誤?? supper03 106 2011-11-26 08:00
980 Re:JSP傳值撈SQL語法有誤?? jimwayne 109 2011-11-27 00:07
1029 Re:JSP傳值撈SQL語法有誤?? pclevin 594 2011-11-27 21:19
» JWorld@TW »  Java 新手區

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8