Download and install the eclipse, java and Mysql
Open eclipse
File-->New-->Class
give the class name as JDBCExample
then copy the follwing code
package testPkg;
import java.sql.*;
//import com.mysql.jdbc.Driver;
public class JDBCExample {
public static void main(String[] args) throws ClassNotFoundException,
SQLException {
String username = "root";
String password = "root";
String tablename = "login";
String fieldname = "uname";
String query = "SELECT " + fieldname + " FROM " + tablename + ";";
/* this chunk of code can appear more or less verbatim */
String url = "jdbc:mysql://localhost:3306/database";
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url, username, password);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
System.out.println("The contents of field " + fieldname + ":");
while (rs.next())
System.out.print(rs.getString(1) + ", ");
// note that getString anomalously starts counting at 1, not 0
System.out.println();
rs.close();
stmt.close();
con.close();
}
}
It will show the error that com.mysql.jdbc.Driver not found.
To resolve this issue use the following step.
right Click on project-->Build Path-->Use external Archives-->then path that mysql-connector-java-5.1.25-bin File
Then Execute the code.