Solved

JDBC rst.getString()

Posted on 2002-05-01
5
253 Views
Last Modified: 2006-11-17
I have a table where a column is defined as a CHAR(50).

When I use JDBC to get a recordset from this table, and then use getString to get the value of that column, I get a string that is padded with white spaces to complete the 50 characters even if the value in the cell is only 2 characters.

Is there a way to just get back the exact value from the table without then having to trim the String?
0
Comment
Question by:afpcos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 92

Expert Comment

by:objects
ID: 6984494
As your column is defined as CHAR(50) I'd say that what it is returning IS the exact value from the table.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 6984667
What objects is getting at is that's how CHAR fields are meant to work - they're of a fixed size and padded. That leaves you two options:

1. Perform the trim at the database level with SELECT TRIM(some_column) FROM some_table.
2. Perform the trim at the application level.

Since SQL is notoriously DBMS-specific, making it a possibility that the TRIM() function is not implemented in your DBMS, you would be safer to do it at the application level. On the other hand, if it is supported in your RDBMS, you might find it enhances performance to do it at the DB.
0
 
LVL 3

Expert Comment

by:rjackman
ID: 6985099
either u trim the String in your java code or trim it in sql
cheers
RJ
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 6985329
You should experiment with trimming at the DB versus trimming at your application, as that's the only way to discover the better performing option. The latter course will always be more portable though.
0
 
LVL 4

Accepted Solution

by:
sumit_only earned 100 total points
ID: 6985569
If possible, then change the definition of the column from CHAR(50) to VARCHAR2(50). Then u wud not need any trimming. But that depends upon whether u can modify the definition now or not. Otherwise, u wud have to trim the string.
Kind regards
Sumit
0

Featured Post

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
Oracle SQL syntax check  without executing 6 107
servlet example 17 59
running on tomcat not jboss eap 7.0 3 31
Java List 4 41
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

733 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