How to get JDBC Connection to MYSQL Database in Java?

Below code snippet shows you to get the JDBC connection in java for MYSQL DB. To get the JDBC connection you will need JDBC Driver Jar for MYSQL Database.

[java]
/****************************************************************************************
* Created on 04-2011 Copyright(c) https://kodehelp.com All Rights Reserved.
****************************************************************************************/
package com.kodehelp.javasql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
* Created by https://kodehelp.com
* Date: 4/29/11
*/
public class GetMySQLConnection {
public static void main(String[] args) throws SQLException, ClassNotFoundException {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost/kodehelp";
String username = "kodehelp";
String password = "kodehelp";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
}
}
[/java]