Вопрос

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