Java Reference
In-Depth Information
VALUES
('Michael',NULL,'Corleone','offers@cosa_nostra.com');
Caution
NULL values are not the same as spaces. A NULL value means that the value is
empty. It is neither a zero, in the case of an integer, nor a space, in the case of a
string.
Using INSERT with JDBC
The code required to use INSERT with JDBC is illustrated in Listing 6-1 . This example is similar in
appearance to the code of Listing 5-1 , which illustrates how to create a table using JDBC. This helps
illustrate how the JDBC API provides a means of passing any desired SQL command to a database
management system.
Listing 6-1: Using INSERT with JDBC
package jdbc_bible.part2;
import java.awt.event.*;
import java.sql.*;
import sun.jdbc.odbc.JdbcOdbcDriver;
public class DataInserter{
static String jdbcDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
static String dbName = "Contacts";
static String urlRoot = "jdbc:odbc:";
public DataInserter(){
registerDriver();
}
public void setDatabaseName(String dbName){
this.dbName=dbName;
}
public void registerDriver(){
try {
Class.forName(jdbcDriver);
DriverManager.registerDriver(new JdbcOdbcDriver());
}
Search WWH ::




Custom Search