我在pl/sql developer直接写sql语句查询时,不用trim函数去除两边空格也能查出来,比如char(5),我就存一个字节的字符,而在java中,就必须去除空格才能查出来,否则查不到。
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@192.168.1.200:1521:test";
String user="test";
String password="test";
Connection conn= DriverManager.getConnection(url,user,password);
PreparedStatement ps=conn.prepareStatement("select * from test where trim(' ' from xxx)=?");
ps.setString(1,"1");
System.out.println(ps.executeQuery().next());
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@192.168.1.200:1521:test";
String user="test";
String password="test";
Connection conn= DriverManager.getConnection(url,user,password);
PreparedStatement ps=conn.prepareStatement("select * from test where trim(' ' from xxx)=?");
ps.setString(1,"1");
System.out.println(ps.executeQuery().next());
所以对于这种DB里面是Char的又要做查询条件的字段,最好使用varchar!