dcsimg
How to insert NULL value into a column ?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Aleksandr_Stserbakov
Posted On:   Tuesday, February 12, 2002 02:39 AM

I have a table with fields of different types (binary(16), varchar, datetime etc). I want to insert NULL into the field with the datetime type. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection connect = DriverManager.getConnection("jdbc:odbc:DB", "sa", ""); PreparedStatement stmt = connect.prepareStatement("INSERT INTO LINKS (oid, startdate) values (?, ?)"); stmt.setBytes(1, new byte[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}); stmt.setNull(2, java.sql.Types.TIMESTAMP); // this line doesn't work and I am getting an exception: Exception in thread "main" java.sql.SQLException: [Microsoft][ODBC D   More>>

I have a table with fields of different types (binary(16), varchar, datetime etc).

I want to insert NULL into the field with the datetime type.



			
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connect = DriverManager.getConnection("jdbc:odbc:DB", "sa", "");
PreparedStatement stmt = connect.prepareStatement("INSERT INTO LINKS (oid, startdate) values (?, ?)");
stmt.setBytes(1, new byte[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0});
stmt.setNull(2, java.sql.Types.TIMESTAMP); // this line doesn't work



and I am getting an exception:

Exception in thread "main" java.sql.SQLException: [Microsoft][ODBC Driver Manager] SQL data type out of
range



I have tried to use java.sql.Types.DATE but with the same effect.



What do I have to do ?

Thanks.    <<Less

Re: How to insert NULL value into a column ?

Posted By:   Aron_Tunzi  
Posted On:   Tuesday, February 12, 2002 06:15 AM

Otherwise you can insert the "null"-value in the PreparedStatement.


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection connect = DriverManager.getConnection("jdbc:odbc:DB", "sa", "");

PreparedStatement stmt = connect.prepareStatement("INSERT INTO LINKS (oid, startdate) values (?, null)");

stmt.setBytes(1, new byte[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0});




Bye, Aron

Re: How to insert NULL value into a column ?

Posted By:   Bozidar_Dangubic  
Posted On:   Tuesday, February 12, 2002 05:57 AM

try setDate() or setTime() with the java.sql.Date or Timestamp objects that are null. so

java.sql.Timestamp tsNull = null ;
stmt.setBytes(1, new byte[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0});
stmt.setTimestamp(2,tsNull);

if this does not work which it should, then you are out of luck with your driver. You need to find a more robust driver because that is where the problem is.
About | Sitemap | Contact