Niharika Jain 0 Newbie Poster

Hey, I've just started with JSP! Was trying my hand at this Shopping cart app.here's the code..

<%@page import ="java.sql.*"%>
<%! Connection con = null;
	String query = null;
	PreparedStatement stmt = null;
	ResultSet rs = null;
%>
<HTML>
<BODY BGCOLOR='ORANGE'>
<CENTER>
<H2>YOUR CART CONTAINS</H2>
<%
	try{
		Class.forName("com.mysql.jdbc.Driver");
		con = DriverManager.getConnection("jdbc:mysql://localhost/shopping_mart?"+"user=root&password=root");
		int no = Integer.parseInt(request.getParameter("SerialNo"));
		String cd = request.getParameter("Code");
		if(no == 1){
			out.print("Mobile");
			query = "select ModelNo,Price from mob_details where Code=?";
		}else if ( no == 2){
			out.print("Home Appliances");
			query = "select ModelNo,Price from ha_details where Code=?";
		}else if ( no == 3){
			out.print("Computer and Peripherals");
			query = "select ModelNo,Price from comp_details where Code=?";
		}else if( no == 4){
			out.print("Shoes");
			query = "select ModelNo,Price from shoe_details where Code=?";
		}else{
			out.print("Music Player");
			query = "select ModelNo,Price from music_player_details where Code=?";
		}
		stmt= con.prepareStatement(query);
		stmt.setString(1,"cd");
		rs = stmt.executeQuery();
		if(no != 2){
		out.println(rs.next());
%>
			<table border =1><th>ModelNo</th><th>Price</th>
			
<%
			while(rs.next()){	
%>
				<tr><td><%=rs.getString(2)%></td><td><%=rs.getInt(3)%></td>
				<td><a href = 'fourth.jsp?SerialNo=<%=no%>&Code=<%=cd%>'>Remove</a></td></tr>

<%			}
			
		}
	}
	catch(SQLException se){ se.printStackTrace();}
	catch(ClassNotFoundException se){ se.printStackTrace();}
	
%>
</table>
</CENTER>
</BODY>
</HTML>

but the rs.next is returning false here! That means it's either not updating the query fired or the query is not being fired at all! I have no clue how to fix this :( Please Help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.