注册 登录
编程论坛 J2EE论坛

求助,为什么点击注册后一直在刷新,数据库里也没载入数据

shangjiang 发布于 2019-06-14 14:37, 5516 次点击
try{ Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e){}
Connection con;
Statement sql;
ResultSet rs;
String condition="INSERT INTO user VALUES";
condition+="("+"'"+name;
condition+="','"+password+"')";
try{
byte [] b=condition.getBytes("ISO-8859-1");
condition=new String(b);
String uri="jdbc:mysql://localhost/shangjiang";
con=DriverManager.getConnection(uri,"root","root");
sql=con.createStatement();
sql.executeUpdate(condition);
con.close();
byte [] c=name.getBytes("iso-8859-1");
name=new String(c);
String mess="恭喜"+name+"注册成功";
jspContext.setAttribute("backMess",mess);
con.close();
}
catch(Exception e){
jspContext.setAttribute("backMess","没有填写用户名或者用户名已经被注册");
}
}
else{
jspContext.setAttribute("backMess","注册失败");}
%>
}
%>
3 回复
#2
林月儿2019-06-14 15:52
报什么错
#3
shangjiang2019-06-14 18:32
没报错。。。
#4
会龙庄2019-07-16 11:33
你参考一下我这个吧。我这个也是注册的。直接在JSP页面写的,没有进行Servlet或者其他方法调用之类的
String clientName=request.getParameter("clientName");
    String clientTelephone=request.getParameter("clientTelephone");
    String clientAddress=request.getParameter("clientAddress");
    String clientEmail=request.getParameter("clientEmail");
    Connection conn=null;
    Statement st=null;
    ResultSet rs=null;
    try{
        Class.forName("com.mysql.jdbc.Driver");
        String url="jdbc:mysql://localhost:3306/system-1001";
        conn=DriverManager.getConnection(url,"root","");
        st=conn.createStatement();
        String sql="INSERT INTO factory_client VALUES('"+clientName+"','"+clientTelephone+"','"+clientAddress+"','"+clientEmail+"')";
        //String sql="INSERT INTO factory_client VALUES('Tony','13983120982','ChongQing','13983120982@')";
        st.executeUpdate(sql);
        response.sendRedirect("../client/success.jsp");
    }catch(Exception e){
        e.printStackTrace();
    }finally{
        st.close();
        conn.close();
1