Java Reference
In-Depth Information
L ISTING 7.2
Continued
System.err.println(sqle.getMessage());
}
}
}
public static void main(String[] args) {
InsertDataApp insertDataApp = new InsertDataApp();
7
insertDataApp.insertData();
}
}
The InsertDataApp application uses the same executeUpdate() method you used to create
your tables. You only change the SQL string that you pass to it, using a basic SQL INSERT
statement instead. You insert data into your Types, Categories, and Titles tables, respectively.
Also notice that you can perform all your inserts using the same Statement object. There is
nothing preventing you from reusing this object, instead of creating a new one for each execu-
tion.
Selecting Data from a Table
The most common SQL statement is the SELECT statement. It gives you the ability to look at
the data stored in your tables. In the previous examples, you created and populated the Movie
Catalog database. In this example, we are going to look at the data you put in these tables, and
we will do it with a SELECT statement. Listing 7.3 contains the source for this example.
L ISTING 7.3
SelectDataApp.java
import java.sql.*;
import java.io.*;
public class SelectDataApp {
public SelectDataApp() {
}
public void selectData() {
Connection con = null;
try {
 
Search WWH ::




Custom Search