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.

3
  • Did you attached the mysql connector jar file to the project classpath? Commented Jan 27, 2015 at 4:43
  • Yes, external JAR is added. Also i am able to get the result in a java file. But not in JSP Commented Jan 27, 2015 at 4:43
  • possible duplicate of JSP MySQL Class.forName error Commented Jan 27, 2015 at 4:46

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

1 Comment

Don't Forget to do the Second Step. This should solve the problem.
0

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

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.