Insert into SQL Server – use NULL vs. empty string?


My table in SQL Server is setup not to allow NULL values. When using runPrepUpdate, if the text field I’m using is blank, runPrepUpdate inserts an empty string instead of using NULL. Is there a way to use NULL by default? I’d prefer to not have to check every field every time for blank strings.



An empty text field is a zero-length string, not a null. If you pass an empty string to system.db.Prep, you get an empty string in your SQL. If you want Null, you need to pass jython’s None for that parameter. You’ll have to script for yourself when and how to do this.