Reputation: 1516
I am working on a project and I need to connect to a database from a jsp file. I have to use the data retrieved from a servlet in the where clause of the query. I am unable to do so correctly. Please post sample codes if possible.
Part of my code is:
//to retrieve data in jsp from servlet
<%! String[] staffData;%>
<% retrievedInfo = (ArrayList) request.getAttribute("filledInfo");%>
<% staffData = (String[]) retrievedInfo.get(0);%>
//After establishing connection:
ResultSet rs = stmt.executeQuery("Select * from EDUCATION where STAFF_NO= <% staffData[0] %>");
Please help me. Please tell me where to make the changes.
Thank you in advance.
Upvotes: 0
Views: 745
Reputation: 4572
Your executeQuery needs to be in a scriptlet tag and you can refer to staffData[0] directly in the code
//to retrieve data in jsp from servlet
<%! String[] staffData;%>
<% retrievedInfo = (ArrayList) request.getAttribute("filledInfo");%>
<% staffData = (String[]) retrievedInfo.get(0);%>
<%
//After establishing connection:
ResultSet rs = stmt.executeQuery("Select * from EDUCATION where STAFF_NO = ' "+staffData[0]+" ' ");
%>
<%
//then iterate through the resultset...
while(rs.next()) {
out.print(rs.getObject(1).toString());
//...etc..
}
%>
Upvotes: 1