So I've created a database in MySQL (version 8.0) and am working on an Eclispe project that should manipulate that database. However, after clicking the submit button via the Tomcat browser I run into a HTTP 500 Internal Error
"com.mysql.jdbc.Driver"
"javax.servlet.ServletException: com.mysql.jdbc.Driver
com.sw.login.doPost(login.java:36)
javax.servlet.http.HttpServlet.service(HttpServlet.java:652)
javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)".
I have installed the mysql connector jar into the project's classpath repeatedly and even tried different versions of the jar file but can not get it to work. I am using a Macbook, Eclispe IDE, and MySQL. Below is a snapshot of the code for the class that should connect to my database. Any help is greatly appreciated and feel free to let me know if I need to clarify anything. Thank you.
public class UserService {
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost:3306/phase2";
// Database credentials
static final String USER = "scott";
static final String PASS = "apple";
public static User retrieveUser(String username, String password) throws SQLException, ClassNotFoundException {
Class.forName("com.mysql.jdbc.Driver");
//STEP 3: Open a connection
System.out.println("Connecting to database...");
Connection conn = DriverManager.getConnection(DB_URL,USER,PASS);
//STEP 4: Execute a query
System.out.println("Creating statement...");
Statement stmt = conn.createStatement();
String sql;
sql = "select * from user where name = \""+ username + "\" AND password = \"" + password + "\"";
ResultSet rs = stmt.executeQuery(sql);
if (rs.next()) {
User user = new User();
user.setName(username);
user.setPassword(password);
return user;
} else {
return null;
}
};