Set - 4

Question 1 :

DB2 Universal claims to support JDBC 2.0, But I can only get JDBC 1.0 functionality. What can I do?

Answer :

DB2 Universal defaults to the 1.0 driver. You have to run a special program to enable the 2.0 driver and JDK support. For detailed information, see Setting the Environment in Building Java Applets and Applications. The page includes instructions for most supported platforms.

Question 2 :

How do I disallow NULL values in a table?

Answer :

Null capability is a column integrity constraint, normally applied at table creation time. Note that some databases won't allow the constraint to be applied after table creation. Most databases allow a default value for the column as well. The following SQL statement displays the NOT NULL constraint:
CREATE TABLE CoffeeTable (

Question 3 :

How to get a field's value with ResultSet.getxxx when it is a NULL? I have tried to execute a typical SQL statement:

Answer :

select * from T-name where (clause);
But an error gets thrown because there are some NULL fields in the table. ?

You should not get an error/exception just because of null values in various columns. This sounds like a driver specific problem and you should first check the original and any chained exceptions to determine if another problem exists. In general, one may retrieve one of three values for a column that is null, depending on the data type. For methods that return objects, null will be returned; for numeric ( get Byte(), getShort(), getInt(), getLong(), getFloat(), and getDouble() ) zero will be returned; for getBoolean() false will be returned. To find out if the value was actually NULL, use ResultSet.wasNull() before invoking another getXXX method.

Question 4 :

How do I insert/update records with some of the columns having NULL value?

Answer :

Use either of the following PreparedStatement methods:
public void setNull(int parameterIndex, int sqlType) throws SQLException
public void setNull(int paramIndex, int sqlType, String typeName) throws SQLException
These methods assume that the columns are nullable. In this case, you can also just omit the columns in an INSERT statement; they will be automatically assigned null values.

Question 5 :

Is there a way to find the primary key(s) for an Access Database table? Sun's JDBC-ODBC driver does not implement the getPrimaryKeys() method for the DatabaseMetaData Objects?

Answer :

// Use meta.getIndexInfo() will
//get you the PK index. Once
// you know the index, retrieve its column name

DatabaseMetaData meta = con.getMetaData();

String key_colname = null;

// get the primary key information
rset = meta.getIndexInfo(null,null, table_name, true,true);
String idx = rset.getString(6);
if( idx != null)
//Note: index "PrimaryKey" is Access DB specific
// other db server has diff. index syntax.
if( idx.equalsIgnoreCase("PrimaryKey"))
key_colname = rset.getString(9);
setPrimaryKey( key_colname );