Reputation: 1040
I have a MySQL database called employee. I want to connect to this database using NetBeans.
I get the following exception:
java.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 ('[email protected]', 'Andrea', 'Stee');";
int rowCount = statement.executeUpdate(query);
} catch (SQLException ex) {
Logger.getLogger(UserDB.class.getName()).log(Level.SEVERE, null, ex);
}
Any suggestion to correct this error? Do I need to add the connector somewhere in my application web?
Upvotes: 1
Views: 82
Reputation: 71
It looks like the url should be updated like this.
String dbURL = "jdbc:mysql://localhost:3306/employee";
Upvotes: 2