aspose file tools*
The moose likes JSP and the fly likes Problem with using multiple queries in single jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem with using multiple queries in single jsp page" Watch "Problem with using multiple queries in single jsp page" New topic
Author

Problem with using multiple queries in single jsp page

sravya perumahanti
Greenhorn

Joined: Jun 06, 2010
Posts: 1

Thanks for your reply sir.
this is my code-

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<body>
<center>
<form>
<table border="0">
<tr> <td> bulbtype </td>
<td> <input type="text" name="bulbtype"></td> </tr>
<tr> <td> bulbwatts </td>
<td> <input type="text" name="bulbwatts">
<input type="submit"/></td>
</tr>

<%
String bulbtype=request.getParameter("bulbtype");

String bulbname=request.getParameter("bulbname");
Class.forName("oracle.jdbc.OracleDriver").newInstance();
String connectionURL = "jdbcracle:thin:@127.0.0.1:1521:XE";
Connection conn = DriverManager.getConnection(connectionURL,"system","sravya");

Statement stmt=conn.createStatement();
Statement st=conn.createStatement();
ResultSet rs1 = stmt.executeQuery("select * from bulb where type="+bulbtype);
ResultSet rs2 = st.executeQuery("select * from bulb where watts="+bulbwatts);
%>
<%while(rs1.next()){%>
<tr> <td>name1</td>
<td> <input type="text" value="<%=rs1.getString("name")%>"></td> </tr>
<%}%>

<%while(rs2.next()){%>
<tr> <td>name2</td>
<td> <input type="text" value="<%=rs2.getString("name")%>"></td> </tr>

<%}%>

</table>
</form>
</center>
</body>
</html>


Im getting this error:

An error occurred at line: 24 in the jsp file: /bulb1.jsp
bulbwatts cannot be resolved
21: Statement stmt=conn.createStatement();
22: Statement st=conn.createStatement();
23: ResultSet rs1 = stmt.executeQuery("select * from bulb where type="+bulbtype);
24: ResultSet rs2 = st.executeQuery("select * from bulb where watts="+bulbwatts);
25: %>
26: <%while(rs1.next()){%>
27: <tr> <td>name1</td>


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please TellTheDetails--we have no idea what code you're using, what error you're getting, etc. ItDoesntWorkIsUseless.
Sam Deka
Greenhorn

Joined: Nov 18, 2014
Posts: 4
Try the following code in place of line no 24 -
ResultSet rs2 = st.executeQuery("select * from bulb where watts='"+bulbwatts+"'");
Sam Deka
Greenhorn

Joined: Nov 18, 2014
Posts: 4
Try the following code in place of line no 24 -
ResultSet rs2 = st.executeQuery("select * from bulb where watts='"+bulbwatts+"'");
Sam Deka
Greenhorn

Joined: Nov 18, 2014
Posts: 4
You haven't defined the string bulbwatts anywhere in your jsp..1st define the string bulbwatts as
String bulbwatts=request.getParameter("bulbwatts");
And then Try the following code in place of line no 24 -
ResultSet rs2 = st.executeQuery("select * from bulb where watts='"+bulbwatts+"'");
This must work..and do let me know
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18992
    
    8

Sam Deka wrote:This must work..and do let me know


The original post was over 4 years ago, so you shouldn't expect a response from the original poster!
Sam Deka
Greenhorn

Joined: Nov 18, 2014
Posts: 4
Haha..i forgot to notice dat..
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Problem with using multiple queries in single jsp page