Java DataSource createTable(DataSource ds, String tableName)

Here you can find the source of createTable(DataSource ds, String tableName)

Description

create Table

License

Open Source License

Declaration

public static void createTable(DataSource ds, String tableName) 

Method Source Code


//package com.java2s;
import javax.sql.DataSource;
import java.sql.Connection;

public class Main {
    private static final String ID_COLUMN_NAME = "id";
    private static final String VALUE_COLUMN_NAME = "a";

    public static void createTable(DataSource ds, String tableName) {
        try (Connection conn = ds.getConnection()) {
            conn.createStatement().executeUpdate(String.format("CREATE TABLE %s (%s INT, %s VARCHAR(255))",
                    tableName, ID_COLUMN_NAME, VALUE_COLUMN_NAME));
        } catch (Exception sqle) {
            throw new RuntimeException("can't create table", sqle);
        }/*from  w  w  w .  j a  va2s .  co m*/
    }
}

Related

  1. countTable(DataSource dataSource, String tableName)
  2. createDataSource()
  3. createDataTable(DataSource dataSource, String tableName)
  4. createDerbyEmbeddedDataSource(Properties props)
  5. createTable(DataSource ds, String ddl)
  6. createTableRecommendation(DataSource dataSource)
  7. createTables(DataSource ds)
  8. createTables(final DataSource ds)
  9. doInsert(DataSource ds, String tableName, int id, String value)