arudolf (2) [Avatar] Offline
#1
Hi,
I followed an example in the book to insert a row with the following code, but receive a
SQLException: JZ0SE: Invalid object type (or null object) specified.

Problem: I don't understand this. Isn't it possible to insert NULL values? Unfortunately there is no example in the book and no example on groovy home.


String country,curr;

String sqlInsert = '''
INSERT INTO IPD_MAPCOUNTRY2CURRENCY (UltimoFlag,COU_CodeISO,CUR_CodeISOSpecific,CUR_CodeISOGeneric, MSC_GovSCSID, MSC_Region, SWC_Name)
VALUES
( ?,?,?,?,?,?,?)
'''

loanspreads.each{
country = countryMap[it.Country_Code]
curr = it.Currency
if(curr == null)
curr = ''

if(country)
dplSql.executeInsert sqlInsert, [0,country,null,null,null,null,null]
}
Mittie (397) [Avatar] Offline
#2
Re: Can't insert null values into database
Hi Andreas,

this forum is for questions regarding the book. Your issue is more of general interest and therefore better to be sent to mailto:user@groovy.codehaus.org. Others may have the same question and more readers will profit from answers there. I hope you don't mind, but we want to avoid running two user lists in parallel.

Nevertheless, I suggest trying the string 'NULL' instead of passing the null reference.

thanks for posting
Dierk
arudolf (2) [Avatar] Offline
#3
Re: Can't insert null values into database
He Dierk,

thank you for your answer. I'll post the question into the suggested forum.
Nevertheless, insert a String 'NULL' isn't the solution. I really want <null> (a.k. undefined ) not NULL as a string.

Best regards

Andreas
Mittie (397) [Avatar] Offline
#4
Re: Can't insert null values into database
smilie

By String 'NULL' I meant using the chars N U L L in the String you are passing to the execute method.

But don't mind. I saw your posting on the list and we will proceed there...

Dierk