setNull « JDBC « Java Database Q&A





1. PreparedStatement setNull(..)    stackoverflow.com

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?
prepStmt.setString(null)
? ...

2. Why does PreparedStatement.setNull requires sqlType?    stackoverflow.com

  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    stackoverflow.com

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    coderanch.com

Hello everyone..here'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    coderanch.com

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(); }