Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: a problem in about CHAR column in the select statement
change your sql statement:
prepareStatement("select id from temp where col = ?");
to:
prepareStatement("select id from temp where col = RPAD( ? ,128)");
or:
prepareStatement("select id from temp where col =
PAD(SUBSTR( ? ,1,128),128)");
HTH
<xinhuang00_at_my-deja.com> wrote in message
news:8k5964$1lm$1_at_nnrp1.deja.com...
> 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
![]() |
![]() |