Hey everybody.
hope somebody can help me. I have this error that says ' javax.servlet.ServletException: Can not issue data manipulation statements with executeQuery() '.
Its something to do with my rs = p.executeQuery();
Thanx for ur time!
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import = "java.sql.*"%>
<%@page import = "java.io.*"%>
<%@page import = "java.util.Properties"%>
<%@page import = "java.io.InputStream"%>
<%@page session = "true"%>
<html>
<head>
<title> Checkout</title>
</head>
<body bgcolor="#228B22">
<font face="Times New Roman,Times" size="+3"> Checkout</font>
<hr>
<%
String notEntered = "";
String connectionURL ="jdbc:mysql://localhost:3306/petshopwebsite";
String driver= "com.mysql.jdbc.Driver";
Connection c = null;
ResultSet rs = null;
Statement st = null;
String password = "";
String username ="root";
try{
Class.forName("com.mysql.jdbc.Driver");
c = DriverManager.getConnection(connectionURL,username, password);
st = c.createStatement();
String productId = request.getParameter("productId");
//String PName = request.getParameter("PName");
//String price = request.getParameter("Price");
String Quantity = request.getParameter("Quantity");
//Properties product = new Properties();
if(rs == null)
{
PreparedStatement p = c.prepareStatement("INSERT INTO order (username,productId,Quantity)"+" VALUES('"+username+"','"+productId+"','"+Quantity+"')");
rs = p.executeQuery();
%>
<
jsp:include page = "signinsuccessful.jsp"/> <%--display this page on the current page--%>
<%
}
else{
%>
<jsp:include page = "Err.jsp"/> <%--display this page on the current page--%>
<%}
%>
<a href="http://localhost:3306/categoryList.jsp">Shop some more!</a>
<%
}catch (Exception e) {
throw (new ServletException(e));
}
finally
{
try { if( rs != null ) rs.close() ; } catch( SQLException ex ) { }
try { if( st != null ) st.close() ; } catch( SQLException ex ) { }
try { if( c != null ) c.close() ; } catch( SQLException ex ) { }
}
%>
</center>
</body>
</html>