Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> a problem in about CHAR column in the select statement

a problem in about CHAR column in the select statement

From: <xinhuang00_at_my-deja.com>
Date: 2000/07/07
Message-ID: <8k5964$1lm$1@nnrp1.deja.com>#1/1

Hi everyone, I really need a help here:
I try to select a record from a table in Oracle by a CHAR column, but the record can not match because of the tailing blanks in the column:

>Class.forName( "oracle.jdbc.driver.OracleDriver" );
>System.out.println ("registered driver");
>Connection conn =
> DriverManager.getConnection

 ("jdbc:oracle:thin:@localhost:1521:orcl","scott", "tiger");
>conn.setAutoCommit (true);
>Statement stmt = conn.createStatement ();
>ResultSet rset;
>rset = stmt.executeQuery("create table temp (id int, col char(128))");
>PreparedStatement pstmt;
>pstmt = conn.prepareStatement("insert into temp (id, col) values
 (?,?)");
>pstmt.setInt(1,1);
>pstmt.setString(2,"aa");
>rset = pstmt.executeQuery();
>pstmt = conn.prepareStatement("select id from temp where col = ?");
>pstmt.setString( 1, "aa" );
>rset = pstmt.executeQuery ();
>while (rset.next ()) {
> System.out.println ("result = " + rset.getObject(1));
>}

However Oracle can not get back any record. But if I change the "aa" to "aa" and following 126 white spaces (add up to 128) and then oracle can match the record.

So, does anyone know how to solve this problem. I really don't want to add so many white spaces in every of my record.

Thank You Very Much !!!

Sent via Deja.com http://www.deja.com/
Before you buy. Received on Fri Jul 07 2000 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US