I have the MySQL JDBC library added to my eclipse project but I still cant connect to a database, the program doesn't throw an error, it just freezes on me. Here's the link to the Library I used http://dev.mysql.com/downloads/connector/j and my current code ( username, host, and passwords omitted.
private Connection connect = null;
private Statement statement = null;
private PreparedStatement preparedStatement = null;
private ResultSet resultSet = null;
@Override
try {
// This will load the MySQL driver, each DB has its own driver
Class.forName("com.mysql.jdbc.Driver");
// Setup the connection with the DB
connect = DriverManager
.getConnection("jdbc:mysql://host:8080/feedback?"
+ "user=******Admin&password=********");
// Statements allow to issue SQL queries to the database
statement = connect.createStatement();
// Result set get the result of the SQL query
System.out.println("Connected");
} catch (Exception e) {
System.out.println("Connection failed");
SOLUTION I had the port wrong, the driver installed improperly AND the database name was wrong. Here was the correct connection line after fixing the driver.
connect = DriverManager
.getConnection("jdbc:mysql://localhost:3306/DataBase?"
+ "user=****Admin&password=*******");