Search code examples
javajdbcvoltdb

creating table in volt-db using jdbc


Is it possible to create a table in voltdb in memory database after it is started

I am trying to create a table in volt-db using JDBC getting

java.sql.SQLException: Invalid SQL statement type.

below is my program

String driver = "org.voltdb.jdbc.Driver";
    String url = "jdbc:voltdb://localhost:21212";
    String sql = "SELECT * FROM Test";
    String sql2 =" create table test1 (id int , name varchar(10))";

    try {
            // Load driver. Create connection.
        Class.forName(driver);
        Connection conn = DriverManager.getConnection(url);

            // create a statement
        Statement query = conn.createStatement();
        ResultSet results = query.executeQuery(sql);
        while (results.next()) {
            System.out.println("Language is " + results.getString(2));
        }
        query.execute(sql2);


             //Close statements, connections, etc.
        query.close(); 

        results.close();
        conn.close();

    } catch (Exception e) {
        e.printStackTrace();
    }

Below is the stacktrace

java.sql.SQLException: Invalid SQL statement type.
at org.voltdb.jdbc.SQLError.get(SQLError.java:40)
at org.voltdb.jdbc.JDBC4Statement$VoltSQL.parseSQL(JDBC4Statement.java:244)
at org.voltdb.jdbc.JDBC4Statement.execute(JDBC4Statement.java:426)
at goliath.analytics.provisioning.Voltdb.main(Voltdb.java:29)

Solution

  • VoltDB v5.0 will support this (due out at the end of January 2015). We have a beta available, contact me for more details or access.

    On VoltDB v4.x you need to precompile your database schema into a catalog and start the database with the catalog or call @UpdateApplicationCatalog with the resulting jar to deploy schema changes.

    John