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

» JWorld@TW » Servlet/JSP 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 多重條件查詢
j_lo2005





發文: 48
積分: 0
於 2007-12-20 09:34 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
請教先進們,
我嘗試寫一個查詢多重條件程式,但一直出錯試了好幾天,可以幫我看一下錯誤出在哪裡嗎?
程式碼
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
<%@ page contentType="text/html;charset=Big5" import="java.sql.*" %>
<%
  String BatchNo = request.getParameter("BatchNo");
  String MaterialType = request.getParameter("MaterialType");
  String VenderNo = request.getParameter("VenderNo");
//
  Class.forName("oracle.jdbc.driver.OracleDriver");
  Connection con =DriverManager.getConnection("jdbc:oracle:thin:@);
  Statement statement = con.createStatement();
  ResultSet rs =null;
 %>
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<%
//==============================================================================
String   strSQL="Select J.IQR_NO BatchNo,J.ITEM_NO MaterialNo,S.INSPECTION_LOT_NO No,S.PIECES_PER_CASE Qty,S.SAMPLE_QTY Sampling,S.QUANTITY OkQty,S.USAGE_DECISION_CODE Judgement,to_char(J.GR_DATE,'yyyy/mm/dd')  IncomingDate,J.SHELF_LIVE ShelfLive,J.SUPPLIER_NAME SupplierName from JOBS J INNER JOIN SAMPLES S ON J.JOB_ID=S.JOB_ID   ";   
  String   str=null;   
  str=(String)request.getParameters("BatchNo");   
  if   (str!=null){   
        if(isFirst==true){   
            strSQL+="where   J.IQR_NO='"+str+"'   ";   
            isFirst=false;   
        }   
  }   
  str=(String)request.getParameters("MaterialType");   
  if   (str!=null){   
        if(isFirst==true){   
            strSQL+="where J.ITEM_NO='"+str+"'   ";   
            isFirst=false;   
        }else{   
            strSQL+='   and  J.ITEM_NO='"+str+"   ;   
        }   
  }   
  str=(String)request.getParameters("VenderNo");   
  if   (str!=null){   
        if(isFirst==true){   
            strSQL+="where   J.SUPPLIER_REF='"+str+"'   ";   
            isFirst=false;   
        }else{   
            strSQL+='   and   J.SUPPLIER_REF='"+str+"   ;   
        }   
  } 
  ResultSet rs=statement.executeQuery(strSQL);
//==============================================================================
while(rs.next())
{

錯誤訊息如下
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
HTTP Status 500 - 
 
--------------------------------------------------------------------------------
 
type Exception report
 
message 
 
description The server encountered an internal error () that prevented it from fulfilling this request.
 
exception 
 
org.apache.jasper.JasperException: Unable to compile class for JSP: 
 
An error occurred at line: 34 in the jsp file: /05_R_RM.jsp
Invalid character constant
31:             strSQL+="where J.ITEM_NO='"+str+"'   ";   
32:             isFirst=false;   
33:         }else{   
34:             strSQL+='   and  J.ITEM_NO='"+str+"   ;   
35:         }   
36:   }   
37:   str=(String)request.getParameters("VenderNo");   
 
Stacktrace:
  org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
  org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
  org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:435)
  org.apache.jasper.compiler.Compiler.compile(Compiler.java:298)
  org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
  org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)
  org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:299)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
 
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.23 logs.
 
--------------------------------------------------------------------------------
 
Apache Tomcat/5.5.23


reply to postreply to post
作者 Re:多重條件查詢 [Re:j_lo2005]
donaldknuth

持續努力中…



發文: 59
積分: 0
於 2007-12-20 09:39 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
是單、雙引號的問題嗎?
檢查一下看看
1
strSQL+='   and  J.ITEM_NO='"+str+"   ;  


reply to postreply to post
愛上JAVA 並不是Cpp的錯

熱愛程式語言的動機是它能讓我在電腦上築夢
作者 Re:多重條件查詢 [Re:j_lo2005]
j_lo2005





發文: 48
積分: 0
於 2007-12-20 10:01 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
d大,
我試著將line34修改成如下
1
            strSQL+="   and  J.MDT_ITEM_NO='"+str+"'   ";   

但出現更多的錯誤訊息
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
HTTP Status 500 - 
 
--------------------------------------------------------------------------------
 
type Exception report
 
message 
 
description The server encountered an internal error () that prevented it from fulfilling this request.
 
exception 
 
org.apache.jasper.JasperException: Unable to compile class for JSP: 
 
An error occurred at line: 21 in the jsp file: /05_R_RM.jsp
The method getParameters(String) is undefined for the type HttpServletRequest
18: //==============================================================================
19: String   strSQL="Select J.IQR_NO BatchNo,J.ITEM_NO MaterialNo,S.INSPECTION_LOT_NO SapNo,S.PIECES_PER_CASE SapQty,S.SAMPLE_QTY Sampling,S.QUANTITY OkQty,S.USAGE_DECISION_CODE Judgement,to_char(J.GR_DATE,'yyyy/mm/dd')  IncomingDate,J.SHELF_LIVE ShelfLive,J.SUPPLIER_NAME SupplierName from JOBS J INNER JOIN SAMPLES S ON J.JOB_ID=S.JOB_ID   ";   
20:   String   str=null;   
21:   str=request.getParameters("BatchNo");   
22:   if   (str!=null){   
23:         if(isFirst==true){   
24:             strSQL+="where   J.IQR_NO='"+str+"'   ";   
 
An error occurred at line: 23 in the jsp file: /05_R_RM.jsp
isFirst cannot be resolved
20:   String   str=null;   
21:   str=request.getParameters("BatchNo");   
22:   if   (str!=null){   
23:         if(isFirst==true){   
24:             strSQL+="where   J.IQR_NO='"+str+"'   ";   
25:             isFirst=false;   
26:         }   
 
An error occurred at line: 25 in the jsp file: /05_R_RM.jsp
isFirst cannot be resolved
22:   if   (str!=null){   
23:         if(isFirst==true){   
24:             strSQL+="where   J.IQR_NO='"+str+"'   ";   
25:             isFirst=false;   
26:         }   
27:   }   
28:   str=request.getParameters("MaterialType");   
 
An error occurred at line: 28 in the jsp file: /05_R_RM.jsp
The method getParameters(String) is undefined for the type HttpServletRequest
25:             isFirst=false;   
26:         }   
27:   }   
28:   str=request.getParameters("MaterialType");   
29:   if   (str!=null){   
30:         if(isFirst==true){   
31:             strSQL+="where J.ITEM_NO='"+str+"'   ";   
 
An error occurred at line: 23 in the jsp file: /05_R_RM.jsp
isFirst cannot be resolved
20:   String   str=null;   
21:   str=request.getParameters("BatchNo");   
22:   if   (str!=null){   
23:         if(isFirst==true){   
24:             strSQL+="where   J.IQR_NO='"+str+"'   ";   
25:             isFirst=false;   
26:         }   
 
An error occurred at line: 25 in the jsp file: /05_R_RM.jsp
isFirst cannot be resolved
22:   if   (str!=null){   
23:         if(isFirst==true){   
24:             strSQL+="where   J.IQR_NO='"+str+"'   ";   
25:             isFirst=false;   
26:         }   
27:   }   
28:   str=request.getParameters("MaterialType");   
 
An error occurred at line: 37 in the jsp file: /05_R_RM.jsp
The method getParameters(String) is undefined for the type HttpServletRequest
34:             strSQL+="   and  J.ITEM_NO='"+str+"'   ";   
35:         }   
36:   }   
37:   str=request.getParameters("VenderNo");   
38:   if   (str!=null){   
39:         if(isFirst==true){   
40:             strSQL+="where   J.SUPPLIER_REF='"+str+"'   ";   
 
An error occurred at line: 23 in the jsp file: /05_R_RM.jsp
isFirst cannot be resolved
20:   String   str=null;   
21:   str=request.getParameters("BatchNo");   
22:   if   (str!=null){   
23:         if(isFirst==true){   
24:             strSQL+="where   J.IQR_NO='"+str+"'   ";   
25:             isFirst=false;   
26:         }   
 
An error occurred at line: 25 in the jsp file: /05_R_RM.jsp
isFirst cannot be resolved
22:   if   (str!=null){   
23:         if(isFirst==true){   
24:             strSQL+="where   J.IQR_NO='"+str+"'   ";   
25:             isFirst=false;   
26:         }   
27:   }   
28:   str=request.getParameters("MaterialType");   
 
An error occurred at line: 46 in the jsp file: /05_R_RM.jsp
Duplicate local variable rs
43:             strSQL+="   and   J.SUPPLIER_REF='"+str+"'   ";   
44:         }   
45:   } 
46:   ResultSet rs=statement.executeQuery(strSQL);
47: //==============================================================================
48: while(rs.next())
49: {
 


reply to postreply to post
作者 Re:多重條件查詢 [Re:j_lo2005]
donaldknuth

持續努力中…



發文: 59
積分: 0
於 2007-12-20 10:08 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
An error occurred at line: 46 in the jsp file: /05_R_RM.jsp
Duplicate local variable rs

試著把多宣告的rs刪除


reply to postreply to post
愛上JAVA 並不是Cpp的錯

熱愛程式語言的動機是它能讓我在電腦上築夢
作者 Re:多重條件查詢 [Re:j_lo2005]
j_lo2005





發文: 48
積分: 0
於 2007-12-20 10:30 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
修改 line 46
1
2
  ResultSet rs=statement.executeQuery(strSQL);
  --> rs=statement.executeQuery(strSQL);

還是一樣錯誤一堆,是這一段有問題嗎?
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
String   strSQL="Select J.MDT_IQR_NO BatchNo,J.MDT_ITEM_NO MaterialNo,S.SAP_INSPECTION_LOT_NO SapNo,S.MDT_PIECES_PER_CASE SapQty,S.SAP_SAMPLE_QTY Sampling,S.MDT_QUANTITY OkQty,S.SAP_USAGE_DECISION_CODE Judgement,to_char(J.MDT_GR_DATE,'yyyy/mm/dd')  IncomingDate,J.MDT_SHELF_LIVE ShelfLive,J.MDT_SUPPLIER_NAME SupplierName from JOBS J INNER JOIN SAMPLES S ON J.JOB_ID=S.JOB_ID   ";   
  String   str=null;   
  str=request.getParameters("BatchNo");   
  if   (str!=null){   
        if(isFirst==true){   
            strSQL+="where   J.MDT_IQR_NO='"+str+"'   ";   
            isFirst=false;   
        }   
  }   
  str=request.getParameters("MaterialType");   
  if   (str!=null){   
        if(isFirst==true){   
            strSQL+="where J.MDT_ITEM_NO='"+str+"'   ";   
            isFirst=false;   
        }else{   
            strSQL+="   and  J.MDT_ITEM_NO='"+str+"'   ";   
        }   
  }   
  str=request.getParameters("VenderNo");   
  if   (str!=null){   
        if(isFirst==true){   
            strSQL+="where   J.MDT_SUPPLIER_REF='"+str+"'   ";   
            isFirst=false;   
        }else{   
            strSQL+="   and   J.MDT_SUPPLIER_REF='"+str+"'   ";   
        }   
  } 
 rs=statement.executeQuery(strSQL);


reply to postreply to post
作者 Re:多重條件查詢 [Re:j_lo2005]
ra





發文: 41
積分: 0
於 2007-12-20 10:39 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
1
2
3
4
5
  將所有的
  str=request.getParameters("XXXX");   
  換成
  str=request.getParameter("XXXX");   
 


reply to postreply to post
作者 Re:多重條件查詢 [Re:j_lo2005]
j_lo2005





發文: 48
積分: 0
於 2007-12-20 11:05 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
謝謝ra大大
1
2
3
    str =(String)request.getParameters("BatchNo");
 
-->    str =(String)request.getParameter("BatchNo");


出現以下錯誤
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
org.apache.jasper.JasperException: Unable to compile class for JSP: 
 
An error occurred at line: 24 in the jsp file: /05_R_RM.jsp
isFirst cannot be resolved
21:   //str=request.getParameters("BatchNo");   
22:     str =(String)request.getParameter("BatchNo");
23:   if   (str!=null){   
24:         if(isFirst==true){   
25:             strSQL+="where   J.IQR_NO='"+str+"'   ";   
26:             isFirst=false;   
27:         }   
 
An error occurred at line: 26 in the jsp file: /05_R_RM.jsp
isFirst cannot be resolved
23:   if   (str!=null){   
24:         if(isFirst==true){   
25:             strSQL+="where   J.IQR_NO='"+str+"'   ";   
26:             isFirst=false;   
27:         }   
28:   }   
29:   //str=request.getParameters("MaterialType");   
 
An error occurred at line: 24 in the jsp file: /05_R_RM.jsp
isFirst cannot be resolved
21:   //str=request.getParameters("BatchNo");   
22:     str =(String)request.getParameter("BatchNo");
23:   if   (str!=null){   
24:         if(isFirst==true){   
25:             strSQL+="where   J.IQR_NO='"+str+"'   ";   
26:             isFirst=false;   
27:         }   
 
An error occurred at line: 26 in the jsp file: /05_R_RM.jsp
isFirst cannot be resolved
23:   if   (str!=null){   
24:         if(isFirst==true){   
25:             strSQL+="where   J.IQR_NO='"+str+"'   ";   
26:             isFirst=false;   
27:         }   
28:   }   
29:   //str=request.getParameters("MaterialType");

請問isFirst變數,還要在哪設阿!!!
感激不盡


reply to postreply to post
» JWorld@TW »  Servlet/JSP 討論區

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

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8