使用JSP从Oracle获取数据

使用JSP从Oracle获取数据,jsp,Jsp,我想使用JSP从Oracle获取数据。应从表单文本框传递多个参数 <form method="post" action="num_post.jsp"> Enter Number: <input name="num" type="text" id="num" /> <input type="submit" name="Submit" value="Submit" /> </form> 这会引发ArrayOutOfBound异常。请尝试此操作 St

我想使用JSP从Oracle获取数据。应从表单文本框传递多个参数

<form method="post" action="num_post.jsp">
Enter Number: <input name="num" type="text" id="num" />

<input type="submit" name="Submit" value="Submit" />
</form>
这会引发ArrayOutOfBound异常。

请尝试此操作

String[]num=request.getParameternum.toString.split

而不是

字符串[]num=request.getParameterValuesUM

====更新=====

正如您所指定的,ArrayIndexOutOfBound表示您正试图从数组中访问索引外的内容。而且,这很清楚

String[] num=(request.getParameter("num").toString()).split(","); // let say array size would be 4
int i=0;  // i initialized by 0

 for(i=0;i<num.length;i++)
 {
      out.println("number Elements       :"+num[i]+"<br/>"); 
 }
  // when control reached here, the value of i will be 4 (which is out of index)
这就是为什么你要摆脱束缚。明白了吗


还有一件事,您在这里编写的查询只适用于检查数组中的一个值。因此,您需要更改查询。它不会向您显示您的预期输出。

请尝试我的解决方案并告知。如果你得到了解决方案,那么就接受它,否则就详细说明你的问题。你在哪里??至少让我知道,不管你的决定与否??我不是Tim Medora,也请详细说明什么不起作用。correction var\uuuuuuuuuuuuuuu\sql查询不接受参数//我可以从textbox检索参数,但sql不会传递该参数以进一步从数据库获取详细信息。字符串sql=从jha中选择*其中num位于'+num[i]+'中@ShaanSonu如果我的解决方案有用,那么接受它并关闭此线程。
<%@page import="java.sql.*"%>
<%@ page import = "java.io.*"%>
<%
 Class.forName("oracle.jdbc.OracleDriver");
 Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
 Statement st=con.createStatement();
 String sql = "SELECT * from jha where num IN '"+num[i]+"'" ;
 ResultSet rs = st.executeQuery(sql);
 %>
String[] num=(request.getParameter("num").toString()).split(","); // let say array size would be 4
int i=0;  // i initialized by 0

 for(i=0;i<num.length;i++)
 {
      out.println("number Elements       :"+num[i]+"<br/>"); 
 }
  // when control reached here, the value of i will be 4 (which is out of index)
"SELECT * from jha where num IN '"+num[i]+"'"   // here value  of i is 4