Java Reference
In-Depth Information
Figure 18.5
Movies table after the UpdateCategory program executes.
import java.sql.*;
public class UpdateCategory
{
public static void main(String [] args)
{
String url = “jdbc:odbc:” + args[0];
int number = Integer.parseInt(args[1]);
String category = args[2];
try
{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
Connection connection =
DriverManager.getConnection(url);
MovieDatabase db = new MovieDatabase(connection);
System.out.println(“Changing category of movie number “
+ number + “ ...”);
db.changeCategory(number, category);
connection.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Figure 18.5 shows the Movies table of the movies.mdb database after the pro-
gram executes. The category of Toy Story was Children, but now it is Comedy.
Callable Statements
A CallableStatement object is used to invoke a stored procedure in a database.
A stored procedure allows you to repeat a sequence of tasks repeatedly in an
efficient manner, much like writing a method in Java. There are several ways
Search WWH ::




Custom Search