回 帖 发 新 帖 刷新版面

主题:jsp,mysql连接问题,救命了,高手,要交论文了

我用JDBC连接 MYSQL,数据库中数据可以读,但不能写入,删除。。。不知道什么问题。弄了好几天了 ,搞不定。。 快交论文了。。
<%@ page contentType="text/html; charset=gb2312" %>

<%@ page language="java" %>

<%@ page import="org.gjt.mm.mysql.Driver" %>

<%@ page import="java.sql.*" %>

<%

//driver

String driverName="org.gjt.mm.mysql.Driver";

//user

String userName="root";

//password

String userPasswd="1234";

//databae

String dbName="ws";

//table

String tableName="user";

//url


//String para1=request.getParameter("name");

//String para2=request.getParameter("gender");

String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;

Class.forName("org.gjt.mm.mysql.Driver").newInstance();

Connection connection=DriverManager.getConnection(url);

Statement statement = connection.createStatement();


String sql="insert into user(id,name,gender) values ('','tom','m')";

ResultSet rs = statement.executeQuery(sql);

rs.close();


statement.close();

connection.close();

//resultset


%>

错误如下:
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Can not issue data manipulation statements with executeQuery().
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
    org.apache.jsp.store_jsp._jspService(store_jsp.java:112)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
    com.mysql.jdbc.Statement.checkForDml(Statement.java:298)
    com.mysql.jdbc.Statement.executeQuery(Statement.java:750)
    org.apache.jsp.store_jsp._jspService(store_jsp.java:92)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

回复列表 (共1个回复)

沙发

语句:"insert into user(id,name,gender) values ('','tom','m')"
values关键词后应没有空格字符.

我来回复

您尚未登录,请登录后再回复。点此登录或注册