Solved

java Strings and sql server varchar

Posted on 2003-10-31
5
261 Views
Last Modified: 2008-02-01
i use visual age for java 3.5
i have a java program that inserts some values in a database on sql server
i insert the values using an object of type "com.ibm.ivj.db.uibeans.Modify"

the problem is that the values of type String are concatenated with spaces when i insert them in fields of type varchar in the sql server
0
Comment
Question by:eng_mohamed_said80
5 Comments
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 63 total points
ID: 9657312
sounds like your JAVA string is being defined with the spaces
or the assignment isn't calculating the correct length...
0
 
LVL 22

Assisted Solution

by:CJ_S
CJ_S earned 62 total points
ID: 9657320
That is because the ANSI_PADDING is turned on by default on varchar columns. The nvarchar datatype does not pad your string.

You can turn off ANSI_PADDING by using the following command:
SET ANSI_PADDING OFF

However, it is recommended to keep the ANSI_PADDING turned on when creating indexes on computed columns.
0
 
LVL 15

Expert Comment

by:namasi_navaretnam
ID: 9658752
CJ_S is absolutely right. You find out what the current setting is by running

SELECT DATABASEPROPERTYEX('DatabaseName', 'IsAnsiPaddingEnabled')

Return Values are,
1 = TRUE
0 = FALSE
NULL = Invalid input
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to shrink a transaction log file down to a reasonable size.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question