<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import ="java.sql.*" %>
<%@ page import = "com.mysql.jdbc.Driver" %>
<jsp:useBean id="vo" class="my.member.MemberVo"/>
<jsp:setProperty property="*" name="vo"/>
<%
Connection conn = null;
Statement stmt = null;
PreparedStatement ps = null;
String queryPerson = new String(); //Query statement
String queryUserInfo = new String();
String queryAccount = new String();
try {
Class.forName("org.gjt.mm.mysql.Driver");
} catch (ClassNotFoundException e ) {
System.out.println("JDBC error");
}
try{
conn = DriverManager.getConnection("jdbc:mysql://mysql2.cs.stonybrook.edu/jaehyeolee", "root", "");
} catch(SQLException e) {
System.out.println("Database Error");
}
System.out.println("Database connected");
try{
stmt = conn.createStatement();
queryAccount = "insert into member values('testID','password','name');";
System.out.println(queryAccount);
stmt.executeQuery(queryAccount);
}catch(SQLException e){
System.out.println("not inserted!");
}finally{
conn.close();
}
%>
This is my really simple mysql query in jsp file. I want to insert values into table member(id, password, name) but it keeps throwing an exception and print "not inserted!".
Does anyone know what cause an exception? I tried to figure it out from yesterday noon but still I don't know the reason.
Please help!
Here is my stack trace!
Database connected
java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
insert into member('userid','password','name') values('jhlee127','108512012','JayZ');
not inserted!
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
at com.mysql.jdbc.StatementImpl.checkForDml(StatementImpl.java:499)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1518)
at org.apache.jsp.member.regFormProc_jsp._jspService(regFormProc_jsp.java:109)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:695)
Instead of:
stmt.executeQuery(queryAccount);
use:
stmt.executeUpdate(queryAccount);
My Java is very rusty, but isn't there some kind of executeUpdate() method that ought to be used here, instead of executeQuery()?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With