This tutorial show you how to work with java and MySql.
1- You have to download MySql Connector(JDBC Driver for MySQL (Connector/J)) driver for java. You can download it from http://www.mysql.com/products/connector/
2- After that you have to extract the connector and put this in the jre folder of your java installation.
3-Finally you have to write the following code in order to connect.
import java.sql.*;
public class SqlConnect {
public static void main(String [] args) {
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Driver Loaded...");
String url = "jdbc:mysql://localhost:3306/your database Name";
Connection con = DriverManager.getConnection(url,"root","mysql");
System.out.println("Connection established.....");
con.close();
} catch(Exception ex) {
System.out.println("File Not found");
}
}//end main
}//end class
The Code is quite self explanatory but if you have any problems in understanding it. Please Let me know.Happy Coding.
No comments:
Post a Comment