We would like to know how to set null value.
/* ww w . j ava 2 s .c o m*/ import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; public class Main { public static void main(String args[]) throws Exception { Connection con = null; Class.forName("oracle.jdbc.driver.OracleDriver"); con = DriverManager.getConnection( "jdbc:oracle:thin:@192.201.32.92:1521:psprd1", "username", "password"); String query = null; ResultSet rset = null; query = "UPDATE t1 " + " SET id = ?"; PreparedStatement stmt = con.prepareStatement(query); // stmt.setInt(paramIndex++, null); stmt.setNull(1, java.sql.Types.INTEGER); stmt.executeUpdate(); stmt.close(); query = "select id from t1 "; stmt = con.prepareStatement(query); rset = stmt.executeQuery(); rset.next(); System.out.println(rset.getString("id")); rset.close(); stmt.close(); con.close(); } }
SQL
create table t1 (id number default 1 ); insert into t1 (id) values (2);