Meaningless Drivel is fun!*
The moose likes JDBC and the fly likes SQL error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL error" Watch "SQL error" New topic
Author

SQL error

Donna Harrington
Ranch Hand

Joined: Aug 08, 2003
Posts: 31
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>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61449
    
  67

If you are having a problem with JDBC, it's best to ask in the JDBC forum, don't you think? Just because you are doing this within a JSP doesn't make it a JSP question.

Moving to the JDBC forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61449
    
  67

Can not issue data manipulation statements with executeQuery() '.


This is a pretty straight-forward message; you are trying to execute a non-query with executeQuery. Look at the javadoc for the PreparedStatement class to find the appropriate method to use when executing non-query statements.
Donna Harrington
Ranch Hand

Joined: Aug 08, 2003
Posts: 31
ok thanx very much
raj edla
Greenhorn

Joined: Apr 24, 2004
Posts: 2
hi,

My answer is use executeUpdate() instead of executeQuery() as Sql statement is Insering data into the table.

Raj
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL error