user544079
user544079

Reputation: 16639

JSP Class Not Found Exception after using import

I am trying to display table data in JSP

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

<html>
<body>
    <% 
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = null;
        conn = DriverManager.getConnection(connection, username, password); 
        String query = "select * from table1";
        Statement stmt = null;
        stmt = conn.createStatement();
        ResultSet rs = null;
        rs = stmt.ExecuteQuery(query);

        while(rs.next()){

       }
    %>

</body>
</html>

It gives cannot find class com.mysql.jdbc.Driver.

Upvotes: 0

Views: 529

Answers (2)

Oliver
Oliver

Reputation: 6260

Your JDBC Driver is not in the Classpath. Do the following:

  1. Put your JDBC Driver in Web-INF/libs
  2. Then Right Click on the Jar and do Add to bulid path.
  3. Run your application again

Upvotes: 1

BAR
BAR

Reputation: 17151

You need to add com.mysql.jdbc.Driver in your classpath.

Simply calling Class.forName(...) is not enough.

Upvotes: 0

Related Questions