0

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.

user544079
  • 16,109
  • 42
  • 115
  • 171
  • Did you attached the mysql connector jar file to the project classpath? –  Jan 27 '15 at 04:43
  • Yes, external JAR is added. Also i am able to get the result in a java file. But not in JSP – user544079 Jan 27 '15 at 04:43
  • possible duplicate of [JSP MySQL Class.forName error](http://stackoverflow.com/questions/24649440/jsp-mysql-class-forname-error) – void Jan 27 '15 at 04:46

2 Answers2

1

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
Oliver
  • 6,152
  • 2
  • 42
  • 75
0

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

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

BAR
  • 15,909
  • 27
  • 97
  • 185