title: Sybase IN and OUT parameters
body: <p>I'm going nuts about how the Sybase JDBC driver handles stored procedures with mixed <code>IN</code> and <code>OUT</code> parameters. Check out this simple stored procedure:</p>
  
  <pre><code>CREATE OR REPLACE PROCEDURE p (IN i1 INT, OUT o1 INT, IN i2 INT, OUT o2 INT)
  BEGIN
      set o1 = i1;
      set o2 = i2;
  END
  </code></pre>
  
  <p>And here's how I'd call it with JDBC:</p>
  
  <pre><code>CallableStatement c = connection.prepareCall("{ call dba.p(?, ?, ?, ?) }");
  c.setInt(1, 1);
  c.setInt(3, 2);
  c.registerOutParameter(2, Types.INTEGER);
  c.registerOutParameter(4, Types.INTEGER);
  c.execute();
  System.out.println(c.getObject(2));
  System.out.println(c.getObject(4));
  </code></pre>
  
  <p>But this results in</p>
  
  <pre><code>1
  null
  </code></pre>
  
  <p>What's going on?? Is that a really wicked bug in the JDBC driver or am I completely missing something? By trial and error, I found this to be a way how it works:</p>
  
  <pre><code>c.setInt(1, 1);
  c.setInt(2, 2);
  c.registerOutParameter(3, Types.INTEGER);
  c.registerOutParameter(4, Types.INTEGER);
  c.execute();
  System.out.println(c.getObject(3));
  System.out.println(c.getObject(4));
  </code></pre>
  
  <p>Now the result is</p>
  
  <pre><code>1
  2
  </code></pre>
  
  <p>Does the JDBC driver secretly re-order <code>IN</code> and <code>OUT</code> parameters??</p>
  
  <p>I'm using SQL Anywhere 12 and jconn3.jar</p>