程序运行没问题,但是程序捕捉到异常,mysql数据库没有插入任何记录,扑捉到的异常是“出现SQLException异常”

lmy497196404 2018-01-03 05:09:29
<%
request.setCharacterEncoding("gb2312");
Object xingming = session.getAttribute("xingming");
Object zhanghao = session.getAttribute("zhanghao");
Object mima = session.getAttribute("mima");
Object youxiang = session.getAttribute("youxiang");
String url = "jdbc:mysql://localhost:3306/dazuoye";
String username = "server";
String password = "12345";
String sql = null;
String jiancha = null;
Connection conn = null;
Statement stmt = null;
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(ClassNotFoundException e){
out.print("加载驱动器类时出现异常");
}

try{
conn = DriverManager.getConnection(url,username,password);

stmt = conn.createStatement();
sql = "INSERT INTO yonghu(xingming,zhanghao,mima,youxiang)"+"VALUES("+xingming.toString()+","+zhanghao.toString()+","+mima.toString()+","+youxiang.toString()+");";
jiancha = "select * from yonghu;";
ResultSet rs = stmt.executeQuery(jiancha);
if(rs.getString(2) == zhanghao.toString() && rs.getString(3) == mima.toString()){
out.print("账号或密码已存在请重新输入");
%>
<a herf = "zhuce.jsp"><input type="button" value="确定"></a>
<%
}if(rs.getString(4) == youxiang.toString()){
out.print("邮箱已存在请重新输入");
%>
<a herf = "zhuce.jsp"><input type="button" value="确定"></a>
<%
}else{
stmt.executeUpdate(sql);
stmt.close();
}
}catch(SQLException e){
out.print("出现SQLException异常");
}finally{
try{
if(conn != null){
conn.close();
}
}catch(SQLException e){
out.print("关闭数据库时出现异常");
}
}
%>
...全文
458 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
lmy497196404 2018-01-03
  • 打赏
  • 举报
回复
求大佬解答,急,在线等

10,606

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 其他
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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