使用PreparedStatement查询oracle char字段无数据解决方法。在项目过程中,由于Oracle Char字段是定长的,当使用PreparedStatement进行查询时,可能会因为空格导致查询结果不对。以下例出解决方案。
1.修改Weblogic或者Tomcat数据库连接池,增加连接属性fixedString=TRUE即可。
Weblogic:

Tomcat:
在server.xml中配置应用的Resource节点,增加fixedString=true
<Context docBase=”project” path=”/” reloadable=”true” source=”org.eclipse.jst.j2ee.server:project”>
<Resource auth=”Container” connectionProperties=”fixedString=true;”
driverClassName=”oracle.jdbc.OracleDriver”
maxActive=”100″ maxIdle=”30″
maxWait=”10000″
name=”***”
password=”***”
type=”javax.sql.DataSource”
url=”jdbc:oracle:thin:@**.**.**:1521:***”
username=”***”/>
</Context>
<Resource auth=”Container” connectionProperties=”fixedString=true;”
driverClassName=”oracle.jdbc.OracleDriver”
maxActive=”100″ maxIdle=”30″
maxWait=”10000″
name=”***”
password=”***”
type=”javax.sql.DataSource”
url=”jdbc:oracle:thin:@**.**.**:1521:***”
username=”***”/>
</Context>
2.在查询语句中调用trim方法去除空格。