phoenix-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ns G <nsgns...@gmail.com>
Subject REG: Issue when creating a Phoenix table through JDBC
Date Thu, 15 Oct 2015 06:11:57 GMT
Hi All,

I have a requirement where in i need to create tables to JDBC (actually
Spring).

I have written the below code

protected Boolean executeScript(final Reader reader, String action, Long
serviceId) throws IOException, SQLException {
        try {
            long start = System.currentTimeMillis();
            final BufferedReader bufferedReader = new
BufferedReader(reader);
            Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
            Connection connection = null;
            String url = "jdbc:phoenix:<regionserver>";
            connection = DriverManager.getConnection(url);
            for (String sql = bufferedReader.readLine(); sql != null; sql =
bufferedReader.readLine()) {
                String trimmedSql = sql.trim();
                final boolean ignore = (trimmedSql.length() == 0 ||
trimmedSql.startsWith("--") || trimmedSql.startsWith("//") ||
trimmedSql.startsWith("/*"));
                if (!ignore) {
                    if (trimmedSql.endsWith(";")) {
                        trimmedSql = trimmedSql.substring(0,
trimmedSql.length() - 1);
                    }
                    Statement stmt = null;
                    /* tables */
                    stmt = connection.createStatement();
                    if (action.equalsIgnoreCase("CREATE") &&
(trimmedSql.toUpperCase().startsWith("CREATE") ||
trimmedSql.toUpperCase().startsWith("UPSERT"))){
                        stmt.execute( MessageFormat.format(trimmedSql,
getSchemNameFromServiceId(serviceId)));
                    } else if (action.equalsIgnoreCase("DROP") &&
trimmedSql.toUpperCase().startsWith("DROP")){
                        stmt.execute( MessageFormat.format(trimmedSql,
getSchemNameFromServiceId(serviceId)));
                    }
                    stmt.close();
/*  SPRING CODE */

                    /*                    if
(action.equalsIgnoreCase("CREATE") &&
(trimmedSql.toUpperCase().startsWith("CREATE") ||
trimmedSql.toUpperCase().startsWith("UPSERT"))){
                        jdbcTemplate.execute(
MessageFormat.format(trimmedSql, getSchemNameFromServiceId(serviceId)));
                    } else if (action.equalsIgnoreCase("DROP") &&
trimmedSql.toUpperCase().startsWith("DROP")){
                        jdbcTemplate.execute(
MessageFormat.format(trimmedSql, getSchemNameFromServiceId(serviceId)));*/
                }
            }
            return true;
        } catch (Exception e) {
            return false;
        }

    }

My .sql file is under src/main/resources/queries folder.

My sql query is

CREATE TABLE TEST (ID UNSIGNED_LONG NOT NULL PRIMARY KEY,  ID1  VARCHAR)
SALT_BUCKETS=32, COMPRESSION='SNAPPY';

I am getting below error

org.apache.phoenix.exception.PhoenixParserException: ERROR 604 (42P00):
Syntax error. Mismatched input. Expecting "STRING_LITERAL", got "<EOF>" at
line 1, column 113.

I saw that a similiar case was raised previously for 4.2 version, where in
the user didnt give a comma, But here the query works when executing
through sqlline.

Can anyone help me please?

Thanks,
Durga Prasad

Mime
View raw message