Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use Oracle jdbc driver fixedString property?
    text
    copied!<p>Oracle pads values in char columns so if I insert "a" in a CHAR(2) column then I cannot get that record by comparing that column to "a", I should get it by comparing it to "a ". Right?</p> <p>To solve this problem the Oracle jdbc driver has the property fixedString but I cannot make it work. (look for <em>fixedString</em> <a href="https://docs.oracle.com/database/121/JAJDB/oracle/jdbc/OracleConnection.html#CONNECTION_PROPERTY_FIXED_STRING" rel="nofollow noreferrer">here</a>)</p> <p>I'm using ojdbc14.jar driver for Oracle 10gR2 and accessing an Oracle 10gR2 database.</p> <p>This is my code:</p> <pre><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:@&lt;host&gt;:&lt;port&gt;:&lt;sid&gt;"; 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(); } </code></pre> <p>The above code executes fine (no exceptions thrown) but the ResultSet is empty after executeQuery().</p> <p>If I change the line (*) for</p> <pre><code>ps.setObject(1, "abc "); </code></pre> <p>Then I get the column I wanted. So it seems the driver is ignoring the fixedString option.</p> <p>I've also tried changing the line (*) for</p> <pre><code>ps.setObject(1, "abc", java.sql.Types.CHAR); </code></pre> <p>But the ResultSet I get is empty again. <strong>What am I missing?</strong></p> <p>Thanks in advance</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload