Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JDBC rst.getString()

Posted on 2002-05-01
5
Medium Priority
?
271 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 300 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn different types of Android Layout and some basics of an Android App.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

604 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