Menu

SQL Offline Syntax Checks

Help
Anonymous
2012-10-03
2014-06-24
  • Anonymous

    Anonymous - 2012-10-03

    Hello,

    is it possible to do SQL Syntax checks with JSqlParser?

    Thanks.

     
  • Anonymous

    Anonymous - 2012-10-03

    I guess yes :-)

    I do it like shown in the example.

            CCJSqlParserManager pm = new CCJSqlParserManager();
            String sql = "SELECT * FROM cool";
            try {
                pm.parse(new StringReader(sql));
            } catch (JSQLParserException e) {
                System.out.println("NOT VALID SQL: " + e.getMessage());
            }
    
     
  • highnoon

    highnoon - 2014-06-23

    I am reading files that have multiple statements in them with comments. I want to verify the SQL syntax in each file.

    Example of one file:

    -- ---------------------------------------------------
    -- - Bubba's SQL
    -- ---------------------------------------------------
    INSERT INTO 'BUBBA_SQL' (id, userid, realname, displayname) VALUES ( 1000000, 'bubba@bubba.com', 'BUBBA JOE', 'Bubba');
    
    UPDATE 'BUBBA_SQL' set realname = 'Bubba Jean' WHERE id = 1000000;
    

    Do I have to tokenize/read each statement individually passing them to the CCJSqlParserManager to verify syntax?

    Or is there a method to allow a return of Statement[] or List<statement> from a file.</statement>

    Having to pre-parse the file before hand looks like what I need to do, but I figured I would ask.

    Thanks ahead of time. :-)

     

    Last edit: highnoon 2014-06-24
  • highnoon

    highnoon - 2014-06-24

    Okay figured out how to read in file with multiple statements.

    CCJSqlParser parser = new CCJSqlParser(reader);
    Statements statementsObj = parser.Statements();
    List<Statement> statementList = statementsObj.getStatements();
    

    then you can iterate over the list.

    I ran into a different problem that I will post in separate thread.

     

    Last edit: highnoon 2014-06-24

Log in to post a comment.

MongoDB Logo MongoDB