Oracle adds values to char columns, so if I insert "a" into the CHAR (2) column, then I cannot get this record by comparing this column with "a", I have to get it by comparing it with "a". Right?
To solve this problem, the Oracle jdbc driver has a fixedString property, but I cannot get it to work. (find fixedString here )
I am using the ojdbc14.jar driver for Oracle 10gR2 and accessing the Oracle 10gR2 database.
This is my code:
try { Properties props = new Properties(); props.put("user", "****"); props.put("password", "****"); props.put("fixedString", true); Class.forName("oracle.jdbc.driver.OracleDriver"); String jdbcUrl = "jdbc:oracle:thin:@<host>:<port>:<sid>"; Connection connection = DriverManager.getConnection(jdbcUrl, props); PreparedStatement ps = connection.prepareStatement( "SELECT * FROM MY_TABLE WHERE MY_TABLE_ID = ?"); ps.setObject(1, "abc"); // (*) // MY_TABLE_ID is CHAR(15) ResultSet rs = ps.executeQuery(); while (rs.next()) { System.out.print("data: "); System.out.println(rs.getString("MY_TABLE_ID")); } rs.close(); ps.close(); connection.close(); } catch (SQLException ex) { ex.printStackTrace(); } catch (ClassNotFoundException ex) { ex.printStackTrace(); }
The above code runs fine (no exceptions are thrown), but the ResultSet is empty after executeQuery ().
If I change the line (*) for
ps.setObject(1, "abc ");
Then I get the desired column. Thus, it seems that the driver is ignoring the fixedString parameter.
I also tried changing the string (*) to
ps.setObject(1, "abc", java.sql.Types.CHAR);
But the ResultSet that I get is empty again. What am I missing?
Thank you in advance
source share