import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

public class JDBCSelect7 {
	public static void main(String[] args) {
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException cnfe) {
			System.err.println("Driver class not found");
			cnfe.printStackTrace();
		}
		Connection con = null;

		try {
			con =
				(Connection) DriverManager.getConnection(
					"jdbc:mysql://localhost/jdbctest/",
					"mario",
					"thePassword");
		} catch (SQLException e) {
			System.err.println("Error establishing database connection");
			Throwable t = e;
			while (t != null) {
   			System.err.println("Type: " + t.getClass().getName());
      		System.err.println("Message: " + t.getMessage());
      		System.err.println("-----");
      		t = t.getCause();
			}
		}

		Statement stmt = null;
		try {
			stmt =
				(Statement) con.createStatement(
					ResultSet.TYPE_SCROLL_SENSITIVE,
					ResultSet.CONCUR_UPDATABLE);
		} catch (SQLException e) {
			System.err.println("Error creating SQL-Statement");
			Throwable t = e;
			while (t != null) {
   			System.err.println("Type: " + t.getClass().getName());
      		System.err.println("Message: " + t.getMessage());
      		System.err.println("-----");
      		t = t.getCause();
			}
		}

		try {
			ResultSet rs = stmt.executeQuery("SELECT * FROM EMPLOYEE;");
			rs.absolute(5);
			System.out.println(rs.getString("FNAME"));

			System.out.println("sleeping ...");
			Thread.sleep(6000);
			System.out.println("awake ...");

			if (rs.rowUpdated() == true) {
				rs.refreshRow();
				System.out.println(rs.getString("FNAME"));
			}

		} catch (SQLException e) {
			System.err.println("Error selecting values from table EMPLOYEE");
			Throwable t = e;
			while (t != null) {
   			System.err.println("Type: " + t.getClass().getName());
      		System.err.println("Message: " + t.getMessage());
      		System.err.println("-----");
      		t = t.getCause();
			}
		} catch (InterruptedException ie) {
			ie.printStackTrace();
		}
	}
}
