I'm new the JSP/Servlets/GlassFish/MySQL (I'm doing this in my free time.) I can't seem to get my MySQL DB connected to my Servlet and my Servlet connected to my JSP page. I've looked up some tutorials but I have not found a solution.
Here is what I have installed:
MySQL DB (newest)
NetBeans IDE EE (newest)
GlassFish (newest)
I'm not sure how to do any of this
Here are my sources:
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="css/main.css" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Index</title> </head> <body> <h1>Index</h1> </body> </html>
root { display: block; } body { text-align: center; font: 12px sans-serif; } h1 { text-align: center; font: 24px sans-serif; }
import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class DBConnect extends HttpServlet { Connection conn; @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } @Override public void init() { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); } catch (InstantiationException ex) { System.err.println(ex.getMessage()); } catch (IllegalAccessException ex) { System.err.println(ex.getMessage()); } catch (ClassNotFoundException ex) { System.err.println(ex.getMessage()); } try { conn = DriverManager.getConnection("jdbc:mysql//localhost:3306/", "root", "root"); } catch (SQLException ex) { System.err.println(ex.getMessage()); } } @Override public void destroy() { try { if (conn != null) { conn.close(); } } catch (SQLException ex) { System.err.println(ex.getMessage()); } } }
Here are the warnings/errors I get:
SEVERE: com.mysql.jdbc.Driver
SEVERE: No suitable driver found for jdbc:mysql//localhost:3306/
Any help is appreciated, thank you.