No suitable driver found for jdbc: mysql: // localhost: 3306 / finalproject

advertisements

this is my test.jsp code

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
import="java.sql.*"
import="java.io.*"
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"      "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Final Project</title>
</head>
<body>
    <center><h1>New Registration Page</h1></center>
    <table border="1" align="center">
        <tr>
            <td>
                <table border="0" align="center" cellpadding="1" cellspacing="1">
                    <tr>
                        <form action=Profile.jsp method="get">
                        <td>First Name*:</td> <!-- we need a button that says show profile then link it here -->
                        <td><input type="text" name="firstname"></td>
                    </tr>
                    <tr>
                        <td colspan="3"><center><input type="submit" value="Submit!"></center></td>
                        </form>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>

This file is connected with the profile.jsp. When i submit the test.jsp,No suitable driver found for jdbc:mysql://localhost:3306/finalproject error comes up from

<%
Class.forName("java.sql.Connection");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/finalproject", "root", "vietforlife");
String firstname=request.getParameter("firstname");

        Statement statement = connection.createStatement();
        ResultSet resultset = statement.executeQuery("SELECT FirstName, LastName, Username, Password1, Password2, Email FROM userid WHERE FirstName = '"+firstname+"'");
%>

I think my database is not connected with the jsp file. I followed the instructions from similar question, but that was not work. can you guys help me?


You are using wrong driver class name
Change

Class.forName("java.sql.Connection");

To

Class.forName("com.mysql.jdbc.Driver");

Have a look at the MySQL docs

Update

it gives java.lang.ClassNotFoundException: com.mysql.jdbc.Driver error.

You need mysql-connector jar in class path in order to avoid ClassNotFoundException.
You can download it from MySQL site

Related Links