JDBC and Stored Procs problem returning ResultSet

[email protected]
Newsgroups gmane.comp.db.mysql.java
Message-ID <[email protected]>
I'm having the dreaded "can't return a result set in the given context"
problem for which I've seen posted quite a bit, but I have yet to find a
solution for Java.  I appreciate any insight.

Thanks in advance,

Mike

I have a simple sproc:

DROP PROCEDURE jdbc_test;
DELIMITER |
CREATE PROCEDURE jdbc_test (in junk INT)
  BEGIN
    DROP TEMPORARY TABLE IF EXISTS t1;
    CREATE TEMPORARY TABLE t1 (id int, value int);

    INSERT INTO t1 values (1, junk);
    INSERT INTO t1 values (2, junk);
    INSERT INTO t1 values (3, junk);

  SELECT * from t1;
  END |
DELIMITER ;

The above sproc runs fine from mysql:

mysql> call jdbc_test(8);
+------+-------+
| id   | value |
+------+-------+
| 1    | 8     |
| 2    | 8     |
| 3    | 8     |
+------+-------+
3 rows in set (0.00 sec)

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql>



BUT when calling it from my java code I get:
java.sql.SQLException: PROCEDURE cevo.jdbc_test can't return a result set
in the given context

Query being executed when exception was thrown:

CALL jdbc_test(8)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
	at com.mysql.jdbc.Connection.execSQL(Connection.java:3124)
	at
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1149)
	at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:790)
	at com.mysql.jdbc.CallableStatement.execute(CallableStatement.java:688)....

Here's the snippet from the Java source:

try {
      cs = conn.prepareCall("{ call jdbc_test(8) }");
      if (cs.execute()) {
        rs = cs.getResultSet();
        while (rs.next()) {
          System.out.println ("RS:" + rs);
          break;
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.out.println ("xxx(), error: " + e.getMessage());
    }

My JConnector version is mysql-connector-java-3.1.12-bin.jar but I've also
tried mysql-connector-java-5.0.3-bin.jar.

The mysql server is version:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 532181 to server version: 5.0.19-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.




-- 
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe:    http://lists.mysql.com/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.