ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Statement和PreparedStatement中char 类型字段的判断不同。

Statement和PreparedStatement中char 类型字段的判断不同。

原创 Linux操作系统 作者:my_vips 时间:2012-06-14 09:53:20 0 删除 编辑
create table testchar(c1 char(10));
insert into testchar(c1) values('a');
--没有空格
select * from testchar where c1='a'
--有一个空格
select * from testchar where c1='a ';
--多于10个空格
select * from testchar where c1='a                          ';
以上三条语句都能检索出来结果。

用PreparedStatement 必须在a后面跟9个空格才能检索出来结果。
String sql = "select c1 from testchar where c1= ? ";
PreparedStatement ps = oracleConn.prepareStatement(sql);
ps.setString(1,'a');
ResultSet rs = ps.executeQuery();
rs没有记录。

--a后面跟9个空格才能检索出来记录
ps.setString(1,'a         ');
ResultSet rs = ps.executeQuery();

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24057587/viewspace-732772/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2012-06-04

  • 博文量
    6
  • 访问量
    18031