package net.dharmaraj;
import java.sql.Connection;
import java.sql.DriverManager;
public class JDBCExample {
public static void main(String[] args) {
System.out.println("-------- MySQL JDBC Connection Testing ------------");
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.out.println("Where is your MySQL JDBC Driver?");
e.printStackTrace();
return;
}//end of Try Catch Block
System.out.println("MySQL JDBC Driver Registered!");
Connection connection = null;
String databaseName = "pkm";
String userName = "root";
String password = "";
String url = "jdbc:mysql://localhost/" + databaseName;
try {
connection = DriverManager.getConnection(url, userName, password);
} catch (Exception e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
return;
}//end of try catch Block
if (connection != null) {
System.out.println("You made it, take control your database now!");
} else {
System.out.println("Failed to make connection!");
}
}//end of Main Method
}//end of Class
JDBC Java Script
Sunday, 17 July 2016
JDBC Quick Start
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment