ps.executeUpdate();报错

a823942262 2015-09-01 11:02:34
<%@ page language="java" import="java.util.*,java.sql.*"pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
String username = request.getParameter("username");
String password = request.getParameter("password");
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "123456");
String sqlQuery = "select count(*) from users where username = ?";
PreparedStatement psQuery = conn.prepareStatement(sqlQuery);
psQuery.setString(1, username);
ResultSet rs = psQuery.executeQuery();
rs.next();
int count = rs.getInt(1);
if (count > 0) {
response.sendRedirect("success.jsp");
psQuery.close();
conn.close();
return;
}

String sql = "insert into users(username,password) values (?, ?)";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, username);
ps.setString(2, password);
ps.executeUpdate();
ps.close();
conn.close();


response.sendRedirect("star.jsp");
%>
希望大家能帮忙看一看哪里出错了
...全文
1519 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ITjavaman 2015-09-02
  • 打赏
  • 举报
回复
javax.servlet.ServletException: java.sql.SQLException: Incorrect integer value: 'a123123' for column 'username' at row 1 你这应该是类型不匹配- -,你插入字符串,但是你字段设置却是整型
解开者 2015-09-02
  • 打赏
  • 举报
回复
数据库的username列设成数了吧
a823942262 2015-09-01
  • 打赏
  • 举报
回复
不行啊,我去掉conn.close();或加到response.sendRedirect("star.jsp");后面也是ps.executeUpdate();报错,
ITjavaman 2015-09-01
  • 打赏
  • 举报
回复
引用 2 楼 a823942262 的回复:
是不是去掉那句?
恩,你下面要引用,把它添加到最下面应该就没问题了
a823942262 2015-09-01
  • 打赏
  • 举报
回复
是不是去掉那句?
ITjavaman 2015-09-01
  • 打赏
  • 举报
回复
conn.close(); 上面的连接的关了,能不报错么
a823942262 2015-09-01
  • 打赏
  • 举报
回复
org.apache.jasper.JasperException: An exception occurred processing JSP page /regiest.jsp at line 26 23: PreparedStatement ps = conn.prepareStatement(sql); 24: ps.setString(1, username); 25: ps.setString(2, password); 26: ps.executeUpdate(); 27: ps.close(); 28: conn.close(); 29: Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:521) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:412) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:723) root cause javax.servlet.ServletException: java.sql.SQLException: Incorrect integer value: 'a123123' for column 'username' at row 1 org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:868) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:797) org.apache.jsp.regiest_jsp._jspService(regiest_jsp.java:93) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:723) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:723) root cause java.sql.SQLException: Incorrect integer value: 'a123123' for column 'username' at row 1 com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073) com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096) com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028) com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490) com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651) com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2683) com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2144) com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2444) com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2362) com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2347) org.apache.jsp.regiest_jsp._jspService(regiest_jsp.java:81) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:723) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
ITjavaman 2015-09-01
  • 打赏
  • 举报
回复
你把错误贴出来
ITjavaman 2015-09-01
  • 打赏
  • 举报
回复
没注意看你IF里面有个return,其实不删也没事,拿你的代码本地测试没有问题

50,759

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧