//The following is how to use JDBC
import java.sql.*;
//First establish a connection
Class.forName("oracle.jdbc.OracleDriver");
//Second make the connection
Connection con = DriverManager.getConnection
(url, "myLogin", "myPassword");
//Third create statements
Statement stmt = con.createStatement();
//Now supply statements. Notice here that we use the DB language
//just as you would type in at a terminal. Here we set up a table.
stmt.executeUpdate("CREATE TABLE VOTERS " +
"(VOTER_ID VARCHAR(32), VOTER VARCHAR(32)," +
"HAS_VOTED INTEGER,");
//JDBC returns results in a ResultSet object, so we need to
//declare an instance of the class ResultSet to hold our results
ResultSet rs = stmt.executeQuery(
"SELECT VOTER_ID, HAS_VOTED FROM VOTERS");
//Getting data one row at a time
//We use the getXXX method of the appropriate type to retrieve
//the value in each column. The following code accesses the values
//stored in the current row of rs and prints a line with the name
//followed by three spaces and the price. Each time the method
//next is invoked, the next row becomes the current row, and
//the loop continues until there are no more rows in rs .
while (rs.next()) {
String s = rs.getString("VOTER_ID");
float n = rs.getInt("HAS_VOTED");
System.out.println(s + " " + n);
}
//Updating
String updateString = "UPDATE VOTERS " +
"SET HAS_VOTED = 1 " +
"WHERE VOTER_ID LIKE 'frog9965tug'";
stmt.executeUpdate(updateString);