日期:2014-05-18  浏览次数:20832 次

提交数据问题
为了向数据库中插入一个新条目,代码如下:
Connection   conn   =   null;
Class.forName( "com.mysql.jdbc.Driver ").newInstance();
String   url   = "jdbc:mysql://localhost/mysqldb?user=abc&password=123&useUnicode=true&characterEncoding=gb2312 ";
conn   =   DriverManager.getConnection(url);
Statement   stmt=conn.createStatement();
String   sql= "insert   meetuser(userid,userpass,username,campaign_id)   values( ' "+request.getParameter( "userid ")+ " ', ' "+request.getParameter( "userpass ")+ " ', ' "+request.getParameter( "username ")+ " ', ' "+request.getParameter( "campaign ")+ " ') ";
stmt.executeQuery(sql);

但抛出异常
javax.servlet.ServletException:   Can   not   issue   data   manipulation   statements   with   executeQuery().

请问是什么问题?

------解决方案--------------------
stmt.executeQuery(sql);
改成
stmt.executeUpdate(sql);
------解决方案--------------------
你的SQL拼写错误,用这个:
String sql = "insert meetuser(userid,userpass,username,campaign_id) values( "+ "request.getParameter( 'userid ') "+ ", "+ "request.getParameter( 'userpass ') "+ ", "+ "request.getParameter( 'username ') "+ ", "+ "request.getParameter( 'campaign ') "+ ") ";