Java SQL Table createTable(Statement statement, String spaceName, String minSeeders, String capacity, String replicationCount)

Here you can find the source of createTable(Statement statement, String spaceName, String minSeeders, String capacity, String replicationCount)

Description

This method defines a space using the ActiveSpaces JDBC Driver which is the same space that is used by most of the normal ActiveSpaces examples such as ASOperations.

License

Open Source License

Declaration

public static void createTable(Statement statement, String spaceName, String minSeeders, String capacity,
        String replicationCount) throws Exception 

Method Source Code

//package com.java2s;

import java.sql.SQLException;
import java.sql.Statement;

public class Main {
    /**/*from   w w  w  .  ja v a  2 s . c  o  m*/
     * This method defines a space using the ActiveSpaces JDBC Driver which is the same space that
     * is used by most of the normal ActiveSpaces examples such as ASOperations. So this example can
     * be used with the other ActiveSpaces examples which use the default example space as long as
     * the metaspace used by this example is the same as is used to run the other ActiveSpaces
     * examples.
     *
     * In ActiveSpaces, a space is the equivalent of a database table. The table columns are called
     * the fields of the space. The types of the columns are mapped to their ActiveSpaces equivalent
     * type by the ActiveSpaces JDBC Driver.
     *
     * Create the default table/space for the normal ActiveSpaces examples, but do not join it. In
     * ActiveSpaces terms, this method defines the space.
     */
    public static void createTable(Statement statement, String spaceName, String minSeeders, String capacity,
            String replicationCount) throws Exception {
        // Format our SQL string to create a table.
        // Notice the use of double-quotes around field names which conflict with SQL keywords.
        // Also notice the comma separated list of ActiveSpaces SpaceDef settings which are appended
        // to the end of the string after the closing parenthesis. The names of the SpaceDef settings
        // are the same as what is specified on the command line for the normal ActiveSpaces examples:
        //   distribution_policy
        //   persistence || persistence_type    <= can use either, examples use persistence
        //   persistence_policy
        //   replication_policy
        //   replication_count
        //   min_seeders
        //   capacity
        //   eviction_policy
        //
        String sql = "CREATE TABLE " + spaceName
                + " (\"key\" INTEGER NOT NULL, value VARCHAR, \"time\" DATETIME, PRIMARY KEY (\"key\"))"
                + " MIN_SEEDERS " + minSeeders + ", CAPACITY " + capacity + ", REPLICATION_COUNT "
                + replicationCount;

        try {
            int result = statement.executeUpdate(sql);
            if (result == 1)
                System.out.println("Space " + spaceName + " created successfully!");
            else if (result == 0)
                System.out.println("A space with the name " + spaceName + " already exists.");
        } catch (SQLException ex) {
            throw new Exception("Error creating space: " + spaceName + "  Error info: " + ex.getMessage());
        }
    }
}

Related

  1. createBagValuesTables(Connection con)
  2. createFreqTable()
  3. createHSQLTables(LineNumberReader reader, Statement statement)
  4. createSourceTable(Connection con)
  5. createTable(Connection dbCon, String tableName, String fields)
  6. createTable(String createTblSql, Connection conn)
  7. createTableAndInsertData(Connection c)
  8. dropTable(String tableName, Connection con)
  9. dumpTable(Connection conn, String TableName, PrintWriter out)