I want to fetch data from Oracle using JSP. Multiple parameters should be passed from the form textbox.
<form method="post" action="num_post.jsp">
Enter Number: <input name="num" type="text" id="num" />
<input type="submit" name="Submit" value="Submit" />
</form>
Here in the text field I want to pass multiple parameters, e.g. 123,456,789,896, etc.
Now in the num_post.jsp I have this code to request the passed parameter in JSP.
<%
String[] num=request.getParameterValues("num");
int i=0;
for(i=0;i<num.length;i++)
{
out.println("number Elements :"+num[i]+"<br/>");
}
%>
Now I want to fetch data from Oracle using the array parameters, for example: num[i]
<%@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);
%>
This throws an ArrayOutOfBound exception.
Try this
String[] num=(request.getParameter("num").toString()).split(",");instead of
String[] num=request.getParameterValues("num");=====UPDATE=====
As you specified, ArrayIndexOutOfBound, which means, you are trying to access out of index from your array. And, it is clear
Now, in your query you are trying to access
4index element, which is not there.That’s why you are getting ArrayIndexOutOfBound. Got it ???
One more thing, the query, which you have written there, is applicable to check only one value from your array. So, you need to change your query. It won’t show you, your expected output.