cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a SCROLL_INSENSITIVE ResultSet using SAP Hana JDBC Driver

Former Member
0 Kudos

public static void main(String[] args) throws ClassNotFoundException {

        // TODO code application logic here

       

        Class.forName("com.sap.db.jdbc.Driver");

       

        String myname = "USERNAME";

        String mysecret = "PASSWORD";

       

       

        Connection connection = null;

      try {                 

         connection = DriverManager.getConnection("jdbc:sap://URL:PORT/?autocommit=false",myname,mysecret);                 

      } catch (SQLException e) {

         e.printStackTrace();

         return;

      }

      if (connection != null) {

         try {

            System.out.println("Connection to HANA successful!");

             java.sql.Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

             java.sql.ResultSet resultSet = stmt.executeQuery("SQL QUERY HERE");

            String hello = resultSet.getString(1);

            System.out.println(hello);

       } catch (SQLException e) {

          e.printStackTrace();

       }

     }

       

       

    }

When I run the above program I get the following exception at Line number 20:

com.sap.db.jdbc.exceptions.jdbc40.SQLDataException: Invalid argument resultSetType, use TYPE_FORWARD_ONLY.

If I replace Line number 20 with:


java.sql.Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

It works without an error. But I need the ResultSet to be able to scroll both ways so that I can use methods such as getRow, previous and last.

What am I doing wrong? The above code works perfectly well for MySQL, Microsoft SQL, Oracle and TeraData. How do I achieve this in SAP Hana?

Accepted Solutions (0)

Answers (1)

Answers (1)

lbreddemann
Active Contributor
0 Kudos

Hey there

Just as in java - Creating a Scroll_Insensitive ResulSet using the SAP Hana JDBC Driver - Stack Overflow the answer is: the SAP HANA JDBC driver doesn't support any other resultset type than FORWARD_ONLY.

Would be interesting to know what your application needs the capability for to keep a result set open and scroll back and forth while making changes to it.

Note that JDBC doesn't actually require compliant drivers to provide this feature, so your relying on an optional feature here.

- Lars