setNull « JDBC « Java Database Q&A

1. PreparedStatement setNull(..)

Java PreparedStatement provides a possibility to explicitely set a Null value. This possibility is:

prepStmt.setNull(<n>, Types.VARCHAR)
Are the semantics of this call the same as when using a setType with a null value?
? ...

2. Why does PreparedStatement.setNull requires sqlType?

  1. According to the java docs of PreparedStatement.setNull: "Note: You must specify the parameter's SQL type". What is the reason that the method requires the SQL type of the column?
  2. I noticed that ...

3. Uses of PreparedStatement setNull

What is the uses of setNull() method in PreparedStatement interface? I looked in this post. It says: Without the setNull(..) method there would be no way to set null values for ...

4. SetNull() in a select PreparedStatement

Hello's my problem... I've a PreparedStatement with these query: "SELECT NAME FROM PERSON WHERE ID_COMPARTMENT=?" ID_COMPARTMENT is a INTEGER column. How I can set null value to the preparedStatement? I've tried ps.setNull(1,java.sql.Types.INTEGER), I haven't any error but the query does't return the correct result. The correct query should be "SELECT NAME FROM PERSON WHERE ID_COMPARTMENT IS NULL" and I think ...

5. SetNull in a PreparedStatement

public class A{ PreparedStatement st; Connection conn; ResultSet rs; String sql="SELECT COL FROM TABLE WHERE A=? AND B=? AND C=? AND D=?"; public A(){ conn = ...get the connection; st = conn.prepareStatement(sql); } public void doSelect(Object []values) { int howManyValues = values.length; for (int i = 0 ; i < length; i++) { st.setObject(i+1,values[i]); } st.executeQuery(); }