MySQL Forums
Forum List  »  Connector/JDBC and Java

connect to MYSQL with servlet
Posted by: Mads Kristensen
Date: July 09, 2013 06:29AM


Okay I have been struggeling with a problem the past two days, and I Cant figure why, so I am pretty much stock. I talked to some people, and they dont know what is wrong either. I want to connect my servlet to a MYSQL database, and I am using MAMP.
This is my code:

import java.sql.Connection;
import java.sql.DriverManager;

public class TestConnection {
public static void main(String[] args) {
try {
System.out.println("Loaded driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/db", "root", "root");
System.out.println("Connected to MySQL");
catch (Exception ex) {

Screenshot of my eclipse:
Ind the left side I have my mysql connector.

My database is called db, and in my database i made two tables: username, and password. Sceenshot is here:

So when I run this servlet I get a 404 error. The screenshot of that is here:

In my servlet I also tried to put this in the con, but with the same result:
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/db1", "root", "root");


Connection con = DriverManager.getConnection("jdbc:mysql://", "root", "root");

The reason I use servlets is because it is an university assigment, where we have to use servlet. I really hope someone can help, because it is driving me crazy :-/ So does anyone out there have a suggestion to what I have to do, to connect to MYSQL database with this servlet?

Best Regards

Options: ReplyQuote

Written By
connect to MYSQL with servlet
July 09, 2013 06:29AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.