title: newbie java error for ClassCastException connecting to remote database using JDBC
body: <p>Anyone know what could be causing the following RUN TIME error in my Java program trying to access an Oracle database on a different Linux server?</p>
  
  <p><code>java.lang.ClassCastException : com.sun.gjc.spi.jdbc40.CallableStatementWrapper40 cannot be cast to oracle.jdbc.OracleCallableStatement</code></p>
  
  <p>I was following the discussion/example on page 4-14 to 4-15 in Oracle's JDBC Developer Guide ( <a href="http://isu.ifmo.ru/docs/doc112/java.112/e10589.pdf" rel="nofollow">http://isu.ifmo.ru/docs/doc112/java.112/e10589.pdf</a> ). I created something similar to that example and it worked fine. Then I started modifying it to get to the below code AND introduced GlassFish into the process, and now I get that error.</p>
  
  <p>Here's my Java code:</p>
  
  <pre><code>public List&lt;Report&gt; GetReports(String var1, String var1, String var3) throws Exception {
      Connection conn;
      CallableStatement cs;
      ResultSet rset;
      String out1; 
  
      Context context = new InitialContext();
      DataSource ds = (DataSource)context.lookup("jdbc/myPool");
      conn = ds.getConnection();
  
      cs = conn.prepareCall( "{call my_proc (?,?,?,?,?)}" );
  
      cs.setString(1, var1);
      cs.setString(2, var2);
      cs.setString(3, var3);
  
      cs.registerOutParameter(4, Types.VARCHAR);
      cs.registerOutParameter(5, OracleTypes.CURSOR);
  
      cs.execute();
  
      out1 = cs.getString(4); 
  
      List&lt;Report&gt; userReports = new ArrayList&lt;Report&gt;();
  
      rset = ((OracleCallableStatement)cs).getCursor(5);
      while ( rset.next() ) {
          Report report = new Report();
          report.col1 = rset.getString("myCol1");
          report.col2 = rset.getString("myCol2");
          userReports.add(report);
      }
  
      if ( rset != null ) {
          try { rset.close(); } catch ( Exception ex ) {}
          rset = null;
      }
  
      if ( conn != null ) {
          try { conn.close(); } catch ( Exception ex ) {}
          conn = null;
      }
  
  return userReports;
  }
  </code></pre>