import [Link].
*;
public class JDBCExample {
// JDBC driver name and database URL
static final String JDBC_DRIVER = "[Link]";
static final String DB_URL = "jdbc:mysql://localhost/EMP";
// Database credentials
static final String USER = "username";
static final String PASS = "password";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try{
//STEP 2: Register JDBC driver
[Link]("[Link]");
//STEP 3: Open a connection
[Link]("Connecting to database...");
conn = [Link](DB_URL,USER,PASS);
//STEP 4: Execute a query to create statment with
// required arguments for RS example.
[Link]("Creating statement...");
stmt = [Link](
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
String sql;
sql = "SELECT id, first, last, age FROM Employees";
ResultSet rs = [Link](sql);
// Move cursor to the last row.
[Link]("Moving cursor to the last...");
[Link]();
//STEP 5: Extract data from result set
[Link]("Displaying record...");
//Retrieve by column name
int id = [Link]("id");
int age = [Link]("age");
String first = [Link]("first");
String last = [Link]("last");
//Display values
[Link]("ID: " + id);
[Link](", Age: " + age);
[Link](", First: " + first);
[Link](", Last: " + last);
// Move cursor to the first row.
[Link]("Moving cursor to the first row...");
[Link]();
//STEP 6: Extract data from result set
[Link]("Displaying record...");
//Retrieve by column name
id = [Link]("id");
age = [Link]("age");
first = [Link]("first");
last = [Link]("last");
//Display values
[Link]("ID: " + id);
[Link](", Age: " + age);
[Link](", First: " + first);
[Link](", Last: " + last);
// Move cursor to the first row.
[Link]("Moving cursor to the next row...");
[Link]();
//STEP 7: Extract data from result set
[Link]("Displaying record...");
id = [Link]("id");
age = [Link]("age");
first = [Link]("first");
last = [Link]("last");
//Display values
[Link]("ID: " + id);
[Link](", Age: " + age);
[Link](", First: " + first);
[Link](", Last: " + last);
//STEP 8: Clean-up environment
[Link]();
[Link]();
[Link]();
}catch(SQLException se){
//Handle errors for JDBC
[Link]();
}catch(Exception e){
//Handle errors for [Link]
[Link]();
}finally{
//finally block used to close resources
try{
if(stmt!=null)
[Link]();
}catch(SQLException se2){
}// nothing we can do
try{
if(conn!=null)
[Link]();
}catch(SQLException se){
[Link]();
}//end finally try
}//end try
[Link]("Goodbye!");
}//end main
}//end JDBCExample