For simple connection confirmation
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class MySQLPractice {
public static void main(String[] args) {
Connection con = null;
try {
//Connect to MySQL
con = DriverManager.getConnection("jdbc:mysql://localhost:8880/database", "root", "pass");
System.out.println("I was able to connect to MySQL.");
} catch (SQLException e) {
System.out.println("Could not connect to MySQL.");
} finally {
if (con != null) {
try {
con.close();
} catch (SQLException e) {
System.out.println("Failed to close MySQL.");
}
}
}
}
}
Recommended Posts