public class DBConnTestClient{
public static void main(String[] args) {
System.out.println("DB Connect Example.");
Connection conn = null;
//mysql db connection
String url = "jdbc:mysql://localhost:3306/db_name";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url,userName,password);
//sql statement here...
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
}
}