Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> a problem in about CHAR column in the select statement
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
![]() |
![]() |