Class JdbcToTableAdapter

java.lang.Object
io.deephaven.jdbc.JdbcToTableAdapter

public class JdbcToTableAdapter extends Object
The JdbcToTableAdapter class provides a simple interface to convert a Java Database Connectivity (JDBC) ResultSet to a Deephaven Table.

To use, first create a result set using your provided JDBC driver of choice:

 Connection connection = DriverManager.getConnection("jdbc:sqlite:/path/to/db.sqlite");
 Statement statement = connection.createStatement();
 ResultSet resultSet = statement.executeQuery("SELECT * FROM Invoice");
 
Then convert the ResultSet to a Table:
 Table resultTable = JdbcToTableAdapter.readJdbc(resultSet);
 

There are several options than can be set to change the behavior of the ingestion. Provide the customized options object to readJdbc(ResultSet, ReadJdbcOptions, String...) like this:

 JdbcToTableAdapter.ReadJdbcOptions options = JdbcToTableAdapter.readJdbcOptions();
 Table resultTable = JdbcToTableAdapter.readJdbc(resultSet, options);
 
There are many supported mappings from JDBC type to Deephaven type. The default can be overridden by specifying the desired result type in the options. For example, convert BigDecimal to double on 'MyCol' via options.columnTargetType("MyCol", double.class).
  • Constructor Details

    • JdbcToTableAdapter

      public JdbcToTableAdapter()
  • Method Details

    • readJdbcOptions

      public static JdbcToTableAdapter.ReadJdbcOptions readJdbcOptions()
      Returns a new options object that the user can use to customize a readJdbc operation.
      Returns:
      a new ReadJdbcOptions object
    • readJdbc

      public static Table readJdbc(ResultSet rs, String... origColumnNames) throws SQLException
      Returns a table that was populated from the provided result set.
      Parameters:
      rs - result set to read, its cursor should be before the first row to import
      origColumnNames - columns to include or all if none provided
      Returns:
      a deephaven static table
      Throws:
      SQLException - if reading from the result set fails
    • readJdbc

      public static Table readJdbc(ResultSet rs, JdbcToTableAdapter.ReadJdbcOptions options, String... origColumnNames) throws SQLException
      Returns a table that was populated from the provided result set.
      Parameters:
      rs - result set to read, its cursor should be before the first row to import
      options - options to change the way readJdbc behaves
      origColumnNames - columns to include or all if none provided
      Returns:
      a deephaven static table
      Throws:
      SQLException - if reading from the result set fails