uk.ac.starlink.table.jdbc

## Class JDBCFormatter

- java.lang.Object
- - uk.ac.starlink.table.jdbc.JDBCFormatter

-     public class JDBCFormatter
      extends java.lang.Object

  Handles conversion of a StarTable into a new table in an RDBMS.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `JDBCFormatter.SqlColumn` Describes a column as it will be written to a table in an RDBMS.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JDBCFormatter(java.sql.Connection conn, StarTable table)` Constructor.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `createJDBCTable(java.lang.String tableName, WriteMode mode)` Writes data from this formatter's input table into the database.
    `JDBCFormatter.SqlColumn` | `getColumn(int icol)` Returns the SqlColumn object describing how a given column of this formatter's input table will be written into the RDBMS.
    `java.lang.String` | `getCreateStatement(java.lang.String tableName)` Returns the text of a suitable CREATE TABLE statement.
    `java.lang.String` | `getInsertStatement(java.lang.String tableName)` Returns the text of a suitable parametric statement for inserting a row.
    `int` | `getSqlType(java.lang.Class<?> clazz)` Returns an SQL type code suitable for a given class.
    `static void` | `main(java.lang.String[] args)` Main method.
    `java.lang.String` | `typeName(int sqlType)` Returns the name used by the connection's database to reference a JDBC type.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### JDBCFormatter

          public JDBCFormatter(java.sql.Connection conn,
                               StarTable table)
                        throws java.sql.SQLException,
                               java.io.IOException

      Constructor.
      Parameters:
        `conn` - JDBC connection
        `table` - input table
      Throws:
        `java.sql.SQLException`
        `java.io.IOException`

  - ### Method Detail

    - #### getCreateStatement

          public java.lang.String getCreateStatement(java.lang.String tableName)

      Returns the text of a suitable CREATE TABLE statement.
      Parameters:
        `tableName` - name of the new SQL table

    - #### getInsertStatement

          public java.lang.String getInsertStatement(java.lang.String tableName)

      Returns the text of a suitable parametric statement for inserting a row. Data placeholders for writable columns will be represented by '?' characters.
      Parameters:
        `tableName` - name SQL table for insertion

    - #### createJDBCTable

          public void createJDBCTable(java.lang.String tableName,
                                      WriteMode mode)
                               throws java.io.IOException,
                                      java.sql.SQLException

      Writes data from this formatter's input table into the database. This method is somewhat misnamed - depending on the write mode, a new table may or may not be created in the database.
      Parameters:
        `tableName` - name of the new table to write to in the database
        `mode` - mode for writing records
      Throws:
        `java.io.IOException`
        `java.sql.SQLException`

    - #### getColumn

          public JDBCFormatter.SqlColumn getColumn(int icol)

      Returns the SqlColumn object describing how a given column of this formatter's input table will be written into the RDBMS. If the value for a given column is `null`, it means that column cannot, and will not, be written.
      Parameters:
        `icol` - column index in input table
      Returns:
        SQL column description

    - #### getSqlType

          public int getSqlType(java.lang.Class<?> clazz)

      Returns an SQL type code suitable for a given class.
      Parameters:
        `clazz` - java class of data
      Returns:
        one of the `Types` codes

    - #### typeName

          public java.lang.String typeName(int sqlType)
                                    throws java.sql.SQLException

      Returns the name used by the connection's database to reference a JDBC type.
      Parameters:
        `sqlType` - type id (as per `Types`)
      Returns:
        connection-specific type name
      Throws:
        `java.sql.SQLException`

    - #### main

          public static void main(java.lang.String[] args)
                           throws java.io.IOException,
                                  java.sql.SQLException

      Main method. Not really intended for use but may be helpful with debugging.
      Throws:
        `java.io.IOException`
        `java.sql.SQLException`