How to Connect to MYSQL database using java


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

public class JDBCExample {

public static void main(String[] argv) {

System.out.println(“——– MySQL JDBC Connection Testing ————“);

try {
} catch (ClassNotFoundException e) {
System.out.println(“Where is your MySQL JDBC Driver?”);

System.out.println(“MySQL JDBC Driver Registered!”);
Connection connection = null;

try {
connection = DriverManager
.getConnection(“jdbc:mysql://localhost:3306/csr_db”,”root”, “password”);

} catch (SQLException e) {
System.out.println(“Connection Failed! Check output console”);

if (connection != null) {
System.out.println(“You made it, take control your database now!”);
} else {
System.out.println(“Failed to make connection!”);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s