Skip to content

Quick Start

Get up and running with General SQL Parser in just a few minutes! This guide will walk you through installation, basic setup, and your first SQL parsing example.

Prerequisites

  • Java 8 or higher (Java 11+ recommended)
  • Maven or Gradle for dependency management
  • IDE (IntelliJ IDEA, Eclipse, or VS Code recommended)

Installation

General SQL Parser is published to Gudu Software's public Maven repository at https://www.sqlparser.com/maven/. Add the repository and a single dependency to your build — nothing to download, install, or configure locally.

Maven

Add this to your pom.xml:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<repositories>
    <repository>
        <id>gudu-public-releases</id>
        <url>https://www.sqlparser.com/maven/</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.gudusoft</groupId>
        <artifactId>gsqlparser</artifactId>
        <version>4.1.5</version>
    </dependency>
</dependencies>

Then build:

1
mvn compile

That's it — Maven downloads gsqlparser-4.1.5.jar from https://www.sqlparser.com/maven/com/gudusoft/gsqlparser/4.1.5/ into your local ~/.m2/ cache on first build.

Gradle

1
2
3
4
5
6
7
repositories {
    maven { url = uri("https://www.sqlparser.com/maven/") }
}

dependencies {
    implementation("com.gudusoft:gsqlparser:4.1.5")
}

Latest version

The current release is 4.1.5. You can always check the latest version by viewing maven-metadata.xml. Maven coordinates are write-once — once a version is published it never changes, so it's safe to pin any specific release.

Running your program

If you want to launch a main class with mvn exec:java, add the exec-maven-plugin to your pom.xml:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>3.1.1</version>
            <configuration>
                <mainClass>QuickStartExample</mainClass>
            </configuration>
        </plugin>
    </plugins>
</build>

Then run:

1
mvn exec:java

Offline / air-gapped installs

If your build environment cannot reach www.sqlparser.com, download the JAR manually and install it into your local Maven cache:

1
2
3
4
5
6
7
curl -O https://www.sqlparser.com/maven/com/gudusoft/gsqlparser/4.1.5/gsqlparser-4.1.5.jar
mvn install:install-file \
    -Dfile=gsqlparser-4.1.5.jar \
    -DgroupId=com.gudusoft \
    -DartifactId=gsqlparser \
    -Dversion=4.1.5 \
    -Dpackaging=jar
1
2
3
4
5
6
7
curl -O https://www.sqlparser.com/maven/com/gudusoft/gsqlparser/4.1.5/gsqlparser-4.1.5.jar
mvn install:install-file ^
    -Dfile=gsqlparser-4.1.5.jar ^
    -DgroupId=com.gudusoft ^
    -DartifactId=gsqlparser ^
    -Dversion=4.1.5 ^
    -Dpackaging=jar

After installing locally you do not need the <repositories> block — the dependency resolves from ~/.m2/.

Your First SQL Parser

Let's create a simple example that parses a SQL statement:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import gudusoft.gsqlparser.TGSqlParser;
import gudusoft.gsqlparser.EDbVendor;

public class QuickStartExample {
    public static void main(String[] args) {
        // Create a parser instance for Oracle SQL
        TGSqlParser sqlparser = new TGSqlParser(EDbVendor.dbvoracle);

        // Set the SQL text to parse
        sqlparser.sqltext = "SELECT employee_id, first_name, last_name " +
                           "FROM employees " +
                           "WHERE department_id = 10 " +
                           "ORDER BY last_name";

        // Parse the SQL
        int result = sqlparser.parse();

        if (result == 0) {
            System.out.println("✅ SQL parsed successfully!");

            // Get basic information about the parsed SQL
            System.out.println("SQL Type: " + sqlparser.sqlstatements.get(0).sqlstatementtype);
            System.out.println("Number of statements: " + sqlparser.sqlstatements.size());

        } else {
            System.out.println("❌ Parse failed!");
            System.out.println("Error: " + sqlparser.getErrormessage());
        }
    }
}

Expected Output

1
2
3
✅ SQL parsed successfully!
SQL Type: sstselect
Number of statements: 1

Database Vendor Support

General SQL Parser supports 30+ database vendors. Here are some common examples:

1
2
TGSqlParser parser = new TGSqlParser(EDbVendor.dbvoracle);
parser.sqltext = "SELECT * FROM dual WHERE ROWNUM = 1";
1
2
TGSqlParser parser = new TGSqlParser(EDbVendor.dbvmssql);
parser.sqltext = "SELECT TOP 10 * FROM employees";
1
2
TGSqlParser parser = new TGSqlParser(EDbVendor.dbvpostgresql);
parser.sqltext = "SELECT * FROM employees LIMIT 10";
1
2
TGSqlParser parser = new TGSqlParser(EDbVendor.dbvmysql);
parser.sqltext = "SELECT * FROM employees LIMIT 10";
1
2
TGSqlParser parser = new TGSqlParser(EDbVendor.dbvbigquery);
parser.sqltext = "SELECT * FROM `project.dataset.table` LIMIT 10";

Common Use Cases

1. SQL Validation

1
2
3
4
5
public boolean isValidSQL(String sql, EDbVendor vendor) {
    TGSqlParser parser = new TGSqlParser(vendor);
    parser.sqltext = sql;
    return parser.parse() == 0;
}

2. Extract Table Names

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import gudusoft.gsqlparser.stmt.TSelectSqlStatement;
import gudusoft.gsqlparser.nodes.TTable;

public void extractTables(String sql) {
    TGSqlParser parser = new TGSqlParser(EDbVendor.dbvoracle);
    parser.sqltext = sql;

    if (parser.parse() == 0) {
        TSelectSqlStatement select = (TSelectSqlStatement) parser.sqlstatements.get(0);

        for (int i = 0; i < select.tables.size(); i++) {
            TTable table = select.tables.getTable(i);
            System.out.println("Table: " + table.getTableName());
        }
    }
}

3. Format SQL

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import gudusoft.gsqlparser.EDbVendor;
import gudusoft.gsqlparser.TGSqlParser;

import gudusoft.gsqlparser.pp.para.GFmtOptFactory;
import gudusoft.gsqlparser.pp.para.GFmtOpt;
import gudusoft.gsqlparser.pp.stmtformatter.FormatterFactory;


public class formatsql {

    public static void main(String args[])
     {

        TGSqlParser sqlparser = new TGSqlParser(EDbVendor.dbvpostgresql);

        sqlparser.sqltext ="WITH upd AS (\n" +
                "  UPDATE employees SET sales_count = sales_count + 1 WHERE id =\n" +
                "    (SELECT sales_person FROM accounts WHERE name = 'Acme Corporation')\n" +
                "    RETURNING *\n" +
                ")\n" +
                "INSERT INTO employees_log SELECT *, current_timestamp FROM upd;";



        int ret = sqlparser.parse();
        if (ret == 0){
            GFmtOpt option = GFmtOptFactory.newInstance();
            String result = FormatterFactory.pp(sqlparser, option);
            System.out.println(result);
        }else{
            System.out.println(sqlparser.getErrormessage());
        }
     }
}

Error Handling

Always handle parsing errors gracefully:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
import gudusoft.gsqlparser.TGSqlParser;
import gudusoft.gsqlparser.EDbVendor;
import gudusoft.gsqlparser.TSyntaxError;

public class QuickStartExample {
    public static void main(String[] args) {
        TGSqlParser parser = new TGSqlParser(EDbVendor.dbvoracle);
        parser.sqltext = "SELECT * FROM"; // Invalid SQL

        int result = parser.parse();
        if (result != 0) {
            System.err.println("Parse Error:");
            System.err.println("Message: " + parser.getErrormessage());
            for(TSyntaxError error : parser.getSyntaxErrors()) {
                System.err.println("Line: " + error.lineNo);
                System.err.println("Column: " + error.columnNo);
                System.err.println("Error: " + error.tokentext);
                System.err.println("Expected: " + error.errortype);
            }
        }
    }
}

Next Steps

Now that you have General SQL Parser running, explore these areas:

Continue Learning

Troubleshooting

Common Issues

Parse Error: Unexpected token

Solution: Check that you're using the correct database vendor. SQL syntax varies between databases.

1
2
3
4
5
6
7
// Wrong
TGSqlParser parser = new TGSqlParser(EDbVendor.dbvoracle);
parser.sqltext = "SELECT TOP 10 * FROM table"; // SQL Server syntax

// Correct
TGSqlParser parser = new TGSqlParser(EDbVendor.dbvmssql);
parser.sqltext = "SELECT TOP 10 * FROM table";

ClassNotFoundException

Solution: Ensure the GSQLParser JAR is in your classpath and all dependencies are included.

OutOfMemoryError

Solution: For large SQL files, consider parsing statements individually or increase JVM heap size.

Getting Help

  • 📖 Check our FAQ for common questions
  • 💬 Visit our Support page for community help
  • 📧 Contact technical support for commercial licenses

Ready for more advanced features? Continue with our comprehensive tutorials or explore specific how-to guides.