import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Main {
public static void main(String[] args) {
Connection connection = null;
try {
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase", "username", "password");
} catch (SQLException e) {
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
}
}
}
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
public class Main {
public static void main(String[] args) {
Connection connection = null;
try {
Properties properties = new Properties();
properties.setProperty("user", "username");
properties.setProperty("password", "password");
properties.setProperty("connectTimeout", "5000");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase", properties);
} catch (SQLException e) {
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
}
}
}
}
}