We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,619 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

shopping cart coding JSP

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 :)

1
Contributor
0
Replies
1
View
Question
Answered
Niharika Jain
Newbie Poster
3 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Self-Answered as of 1 Year Ago

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0559 seconds using 2.69MB