cancel
Showing results for 
Search instead for 
Did you mean: 

Getting SQL Exception when inserting Empty String or null values....

Former Member
0 Kudos

Hi,

I am migrating a J2ee project to SAP netweaver server. As a part of the project, some time i need to store empty string, null values or spaces to the databse tables. But when ever I am trying to insert a record in to the DB with some field values as empty strings (""), I am getting a SQL Exception as given below,

"<b>com.sap.sql.log.OpenSQLException: Cannot assign an empty string to host variable 3</b>"

When i tried to insert a record with empty string as some field values directly in to the table using SQL(insert into.. )statement, I am able to insert the record.

I need to pass the empty string based on the application requirement

Your help and suggestions solicited in this regard.

Thankyou,

Sudheesh K S....

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Sudheesh,

Try inserting into the DB by giving specific column names in the SQL query. This will automatically insert a blank in the DB field which you are not specified in the Query.

Hope it helps.

Regards,

Maheswaran.B

Former Member
0 Kudos

Hello sir,

But I am using Entity bean with CMP.

As i stated before I am facing the problem only when i am calling the bean and creating a new record from the application. When i tried to insert the record directly using SQL, the query executed successfully...

Sir, Any idea regarding this?

Regards,

Sudheesh

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi sudheesh,

The problem is definately because of the definition of data types used for the fields.

Please check up what are the constraints you have put on the various characters.

There is a link "creating data types in Java dictionary"

http://help.sap.com/saphelp_nw04s/helpdata/en/39/5b033eec2bc452e10000000a114084/frameset.htm

Check if the above link helps

If you are defining the datatype as string,there is something interesting.

String

VARCHAR (N)

Varying length character strings with a maximum length of N characters

1 - 1000 Characters

Yes

LONGVARCHAR(N)

Varying length character strings with a maximum length of N characters

1001 - 1333 Characters

No

CLOB

Varying length character strings of virtually unlimited size

357.913.941 Characters

No

I found this sepcification in the link "Open sql data types for Java Dictionary"

So as you can see for portability of jdbc data,the length of string should atleast be '1'.

Regards,

Harish

(Please award points for helpful answers)

Former Member
0 Kudos

Hi,

Is this problem occuring only for column 3 or any other column.

Can you tell us how you have defined the table in the dictionary.

Regards,

Harish

Former Member
0 Kudos

Hello Harish,

We are in contact again. No If i put any value to colums 3 then the exception will occur for the next column with empty space as the value.

I declared the fields in the table as string by specifying the length required for the field.

Is it correct?

With best regards,

Sudheesh...