Java Reference
In-Depth Information
Title Name = High Plains Drifter
Title Rating = PG
Title Price = 29.95
Title Quantity = 10
Title Name = Cape Fear
Title Rating = NR
Title Price = 6.99
Title Quantity = 21
7
Title Name = The Last Emperor
Title Rating = PG
Title Price = 19.95
Title Quantity = 12
Updating Tables
Another SQL command we need to examine is the UPDATE statement. It looks for a matching
condition and makes the specified changes if the WHERE clause is true. An example of this
would be if you sold seven copies of The Last Emperor . You would need to update its quantity
to 5. The example in Listing 7.4 does just that.
L ISTING 7.4
UpdateDataApp.java
import java.sql.*;
public class UpdateDataApp {
public UpdateDataApp() {
}
public void updateData() {
Connection con = null;
try {
// Load the Driver class file
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
// Make a connection to the ODBC datasource Movie Catalog
con = DriverManager.getConnection(“jdbc:odbc:Movie Catalog”,
“”, “”);
// Create the statement
 
Search WWH ::




Custom Search