I want to connect to a database using Java
. I use this code:
public static Connection getConnection() throws Exception {
try {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:sqlserver://localhost;integratedSecurity=true;";
String username = "root";
String password = "mysql";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
System.out.println("Connected");
return conn;
} catch(Exception e) {
System.out.println(e);
}
return null;
}
But I don't know the correct default url
and driver
property values. I use MySQLWorkBench
.