Search code examples
griddb

Why does GridDB's JDBC driver throw the JDBC_OPTIONAL_FEATURE_NOT_SUPPORTED error?


I am working on a Java application using GridDB as the database and the JDBC driver for GridDB. While executing an SQL query to retrieve the auto-generated keys, I encounter the following exception:

java.sql.SQLFeatureNotSupportedException: JDBC_OPTIONAL_FEATURE_NOT_SUPPORTED
at com.toshiba.mwcloud.gs.sql.internal.StatementAdapter.getGeneratedKeys(StatementAdapter.java:123

    
  1. Database: GridDB 5.1 CE

  2. JDBC Driver: GridDB JDBC Driver version 5.1

  3. Query Executed:

Connection connection = DriverManager.getConnection("jdbc:gs://Farwa:20001/default", "GridDB", "admin786");
String query = "INSERT INTO Customers (Customer_ID, Customer_name) VALUES (1, Ali)";
PreparedStatement preparedStatement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
preparedStatement.setString(1, "Value1");
preparedStatement.setString(2, "Value2");
int rowsAffected = preparedStatement.executeUpdate();
ResultSet generatedKeys = preparedStatement.getGeneratedKeys();
if (generatedKeys.next()) {
    System.out.println("Generated Key: " + generatedKeys.getInt(1));
}
CREATE TABLE Customers (
    Cusomter_ID NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    Customer_Name VARCHAR2(50)
    
);

Issue:

The error occurs because the getGeneratedKeys() method is not supported by the GridDB JDBC driver.


Solution

  • Generated keys are the value of columns that are declared as generated; e.g. IDENTITY, AUTO_INCREMENT, and so on in various SQL dialects.

    GridDB's SQL doesn't support any column types of this nature. Therefore, it is appropriate for the JDBC driver to throw SQLFeatureNotSupportedException when you call getGeneratedKeys().


    In your question, you give us the following table declaration.

    CREATE TABLE Customers (
        Cusomter_ID NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
        Customer_Name VARCHAR2(50)
        
    );
    
    1. That is not valid SQL according to GridDB SQL syntax described here. (Retrieved 2024-12-18)

    2. I confirmed 1. by looking at the source code of the GridDB SQL parser. For example, GENERATED and IDENTITY are not tokens.

    3. The typo in the first column's name leads me to believe that this is not "real".