문제

I am trying to connect to my database and do something using post method but my compiler gives me a ClassNotFoundException on this line:

Class.forName("com.mysql.jdbc.Driver");

What do I need to do to fix this?

Here is my post function:

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException{
    String user = request.getParameter("username");
    String pwd = request.getParameter("password");
    PrintWriter out= response.getWriter();
    try{  
        Class.forName("com.mysql.jdbc.Driver");
        con=DriverManager.getConnection(  
        "jdbc:mysql://localhost/e-commerce", "root1" , "****");
        stmt = con.createStatement();
        String sql = "SELECT * UserFirstName FROM USERS ";
        ResultSet rs = stmt.executeQuery(sql);
    }catch (SQLException ex) {
        System.out.println("SQLException: " + ex.getMessage());
        System.out.println("SQLState: " + ex.getSQLState());
        System.out.println("VendorError: " + ex.getErrorCode());
    }

    out.println("<font color=red>Either user name or password is wrong.</font>");
    out.println(name);
}

I am using Netbeans 8.0.

도움이 되었습니까?

해결책

In the bar the netbeans project, select the Services tab, then where it says right click database, new connection, then configure your connection and go. Remember that the engine of the database must have previously installed in your operating system

다른 팁

you must add the jar containing the class com.mysql.jdbc.Driver to your classpath. you can find it here http://dev.mysql.com/downloads/connector/j/5.0.html

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top