I have a mysql database called employee.
I want to connect to this database using netbeans.
I get the following exception:
ava.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Failed to parse the host:port pair ‘localhost:3306:employee’.
My code is:
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
try {
String dbURL = "jdbc:mysql://localhost:3306:employee";
String userName = "root";
String password = "admin";
Connection connection = DriverManager.getConnection(dbURL, userName, password);
Statement statement = connection.createStatement();
String query = "INSERT INTO user Email, FirstName, LastName) VALUES ('xx@gmail.com', 'Andrea', 'Stee');";
int rowCount = statement.executeUpdate(query);
} catch (SQLException ex) {
Logger.getLogger(UserDB.class.getName()).log(Level.SEVERE, null, ex);
}
anny suggestion to correct this error?
Does I need to add the connector somewhere in my application web?
>Solution :
It looks like the url should be updated like this.
String dbURL = "jdbc:mysql://localhost:3306/employee";