I have tried to connect with the mysql database by the JDBC. But I am no able to connect it with the vs code.I just have a question that we need the mavan project to connect with db always. I have also add the code please Refer and suggest me how can i connect with the db. Thanks!
The error that i have got while connecting. enter image description here
package JDBC;
import java.sql.Connection;
import java.sql.DriverManager;
public class createDb {
// JDBC and database properties.
private static final String DB_DRIVER = "com.mysql.jdbc.Driver";
private static final String DB_URL = "jdbc:mysql://localhost:3306/";
private static final String DB_USERNAME = "root";
private static final String DB_PASSWORD = "root";
public static void main(String args[]) {
Connection conn = null;
try {
// Register the JDBC driver
Class.forName(DB_DRIVER);
// Open the connection
conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
if (conn != null) {
System.out.println("Successfully connected.");
} else {
System.out.println("Failed to connect.");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}