0

I have some code to test the migration of a sybase database into a SQL Server one. A part of the testing is to execute stored procedures in both databases and compare the results.

I have a stored procedure that returns 10+ result sets. The issue is that with Sybase, when I try to switch from one result set to the other, it fails. The 2nd result set ends up being null which means I'm only getting result set back in Sybase. This code works for SQL server.

Any idea how to get this to work for Sybase?

I'm using java 8 and JConn 4.

 public static void storedProc(){

        String strConnectionString = "jdbc:sybase:Tds:host:port?";
        String strUsername = "username";
        String strPassword = "pass";

        String strQuery = "exec storedprocedure";

        Connection connection = JDBCUtils.databaseConnection(strConnectionString, strUsername, strPassword);

        PreparedStatement preparedStatement = connection.prepareStatement(strQuery, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

        int intResulSet = 0;
        int count = 0;
        try{

            preparedStatement.executeQuery();

            ResultSet resultSet = preparedStatement.getResultSet();

            while (resultSet!=null) {
                intResulSet +=1;
                System.out.println(resultSet);
                System.out.println("Result Set: " + intResulSet);
                if (!resultSet.next()) {
                    System.out.println("Result Set is Empty");
                } else {
                    do {
                        count+=1;
                        System.out.println(count);
                    } while (resultSet.next());
                }
                preparedStatement.getMoreResults(Statement.CLOSE_CURRENT_RESULT);;
                resultSet = preparedStatement.getResultSet();
                System.out.println(resultSet);

            }

        } catch (SQLException e) {
            System.out.println(e.getMessage());
        }

       connection.close();
}

This is just a piece of my code. Not doing any of the comparisons here. This is just trying to successfully switch from one resultset to the next.

This same exact code switches through and prints results for all the result sets in SQL, but unfortunately, no luck in Sybase.

I've also tried to use callable statement instead of prepared statement and same issue.

AlwaysLearning
  • 7,915
  • 5
  • 27
  • 35
Aztg
  • 33
  • 4

0 Answers0