Accessing CHAR columns in java
Posted in 1998
This is a multi-part message in MIME format. ------=_NextPart_000_0042_01BDA9A7.874F5DC0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable As I understand it, when a CHAR(n) field is retrieved from the database in Java (using JDBC), the driver will convert the field to a Java String object of length n, padding spaces at the end if necessary. And, when a String object is sent to a CHAR(n) field, the driver and/or database will add any necessary padding spaces to the end of the string to bring it up to length n. When coding in I-4gl, it seemed that any character variable written to the database had its trailing blanks clipped, or at least the INPUT statement of character variables did that. I guess my question is, suppose you have a CHAR(4) column for say "state" and you store the values of "TN", "GA", and "FL" in that column. Each of those values are two-characters each. Does Informix store the values as "TN ", "GA ", and "FL ", with two blank spaces padded at the end for each value? I'm trying to determine a strategy for handling these CHAR columns in java. I think I definitely want to trim the white space at the end whenever I retrieve a CHAR column from the database. Does anyone have any thoughts or guidance? Thanks, Candy -- Candy McCall ONLINE Computing, Inc. (candym@olcinc.com) ------=_NextPart_000_0042_01BDA9A7.874F5DC0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN"> <HTML> <HEAD> <META content=3Dtext/html;charset=3Diso-8859-1 = http-equiv=3DContent-Type> <META content=3D'"MSHTML 4.71.1712.3"' name=3DGENERATOR> </HEAD> <BODY bgColor=3D#d8d0c8> <DIV><FONT color=3D#000000 size=3D2>As I understand it, when a CHAR(n) = field is=20 retrieved from the</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2>database in Java (using JDBC), the = driver will=20 convert the</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2>field to a Java String object of = length n,=20 padding spaces at</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2>the end if necessary. And, = when a String=20 object is sent to</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2>a CHAR(n) field, the driver and/or = database will=20 add any</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2>necessary padding spaces to the end = of the=20 string to bring it up to</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2>length n. When coding in = I-4gl, it seemed=20 that any</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2>character variable written to the = database had=20 its trailing blanks</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2>clipped, or at least the INPUT = statement of=20 character variables</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2>did that. I guess my question = is, suppose=20 you have a CHAR(4)</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2>column for say "state" and = you store=20 the values of "TN", "GA",</FONT></DIV> <DIV><FONT size=3D2>and "FL" in that column. Each of = those values=20 are two-characters</FONT></DIV> <DIV><FONT size=3D2>each. Does Informix store the values as = "TN =20 ", "GA ", and</FONT></DIV> <DIV><FONT size=3D2>"FL ", with two blank spaces padded = at the end=20 for each value?</FONT></DIV> <DIV><FONT size=3D2>I'm trying to determine a strategy for handling = these=20 CHAR</FONT> </DIV> <DIV><FONT size=3D2>columns in java. I think I definitely want to = trim=20 the</FONT> </DIV> <DIV><FONT size=3D2>white space at the end whenever I retrieve a CHAR=20 column</FONT> </DIV> <DIV><FONT size=3D2>from the database. Does anyone have any = thoughts=20 or</FONT> </DIV> <DIV><FONT size=3D2>guidance?</FONT> </DIV> <DIV><FONT size=3D2></FONT> </DIV> <DIV><FONT size=3D2>Thanks,</FONT></DIV> <DIV><FONT size=3D2>Candy</FONT></DIV> <DIV><FONT size=3D2></FONT><FONT color=3D#000000 size=3D2>--<BR>Candy = McCall<BR>ONLINE=20 Computing, Inc.<BR>(<A=20 href=3D"mailto:candym@olcinc.com">candym@olcinc.com</A>)</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2></FONT> </DIV> <DIV> </DIV></BODY></HTML> ------=_NextPart_000_0042_01BDA9A7.874F5DC0--