我在结果集行收到错误

时间:2016-03-08 11:58:01

标签: java jsp jdbc

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

<%
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/user","root","");
        Statement st = con.createStatement();

        String name = request.getParameter("name");
        String username = request.getParameter("user");
        String pass = request.getParameter("pas");
        String cpass = request.getParameter("cpas");


        String sql2 = "select * from user where user='"+username+"';";
        ResultSet rs = st.executeQuery(sql2);
        if(rs.next())
        {
            response.sendRedirect("index.html?err=Username already taken");
        }
        else
        {

        String sql = "insert into user values('"+name+"', '"+username+"','"+pass+"',"+cpass+");";
        st.executeUpdate(sql);

        response.sendRedirect("blank.html");
        }

%>

1 个答案:

答案 0 :(得分:-1)

的Class.forName( “com.mysql.jdbc.Driver”)的newInstance();         Connection con = DriverManager.getConnection(“jdbc:mysql:// localhost:3306 / user”,“root”,“”);         Statement st = con.createStatement();

    String name = request.getParameter("name");
    String username = request.getParameter("user");
    String pass = request.getParameter("pas");
    String cpass = request.getParameter("cpas");


    String sql2 = "select * from user where user='"+username+"';";
    ResultSet rs = st.executeQuery(sql2);
    if(rs != null && rs.next())
    {
        response.sendRedirect("index.html?err=Username already taken");
    }
    else
    {

    String sql = "insert into user values('"+name+"', '"+username+"','"+pass+"',"+cpass+");";
    st.executeUpdate(sql);

    response.sendRedirect("blank.html");
    }