日期:2014-05-17  浏览次数:21003 次

使用JDBC连接MySQL失败
使用JDBC连接MySQL数据库时连接失败,并返回java.lang.NullPointerException异常,为什么会发生空指针异常?求大神指点~~
<body>
        <%
            String userName=
                    new String(request.getParameter("userName").getBytes("ISO-8859-1"),"UTF-8");
            String password=
                    new String(request.getParameter("password").getBytes("ISO-8859-1"),"UTF-8");
            Connection con=null;
            Statement st=null;
            ResultSet rs=null;
            if(userName.equals(""))
            {
                response.sendRedirect("login.jsp");
            }
            try{
                Class.forName("com.mysql.jdbc.Driver");
                String url="jdbc:mysql://localhost:3306/eims?useUnicode=true&characterEncoding=gbk";
                con=DriverManager.getConnection(url, "root", "6785098");
                st = con.createStatement();
                String query = "select * from user where userName = '" + userName + "'";
                rs = st.executeQuery(query);
                if (rs.next())
                {
                    String query2 = "select * from user where password = '" + password + "'";
                    rs = st.executeQuery(query2);
                    if (rs.next())
                    {
                        response.sendRedirect("main/main.jsp");
&nbs