This is a free java command line application which can be used to execute SQL batch files.
Logging is provided through System.out (stdout) and System.err (stderr).
The tool is completely free, and full source code is included.
Comments welcome!
java -cp <classPath> sjsql <driverClass> <jdbcString> <userName> <password> <sqlFile>
driver. Note that on Windows, the java classpath uses a semicolon (;) to separate paths.
java -cp .;jtds-1.2.jar sjsql net.sourceforge.jtds.jdbc.Driver jdbc:jtds:sqlserver://localhost:1433 user pass infile.sql
. Note that on Linux, the java classpath uses a colon (:) to separate paths.
java -cp .:mysql-connector-java-3.1.13-bin.jar sjsql com.mysql.jdbc.Driver jdbc:mysql://localhost:3306/myDatabase user pass infile.sql
driverClass - JDBC driver class name, eg: com.mysql.jdbc.Driver jdbcString - JDBC connection string, eg: jdbc:mysql://localhost:3306/myDatabase userName - database username password - database password sqlFile - list of SQL statements, one per line
--start 123 - line number to start from, for resuming after errors. Default is 1. --ignore-nodata - if query response is no-data (eg: INSERT statements) then don't log. Default is log all results. --log-queries - include each query in the output. Default is to only log results. --batch 500 - send 500 queries at a time, wrapped in a transaction (good for remote connections). --batch all - wrap entire file in a transaction, call rollback on failure.
Line numbers start from 1 (not 0) Each line is treated as a separate query. Semicolons or other query-terminators are optional and will be ignored. Query logging is sent to System.out (can be redirected with >results.log) Other output is sent to System.err (can be redirected with 2>output.log)
[sjsql] Exception at line 70000: java.lang.OutOfMemoryError: Java heap space
java.lang.OutOfMemoryError: Java heap space
at java.lang.String.toCharArray(String.java:2726)
at net.sourceforge.jtds.jdbc.SQLParser.<init>(SQLParser.java:234)
at net.sourceforge.jtds.jdbc.SQLParser.parse(SQLParser.java:155)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeImpl(JtdsStatement.java:625)
at net.sourceforge.jtds.jdbc.JtdsStatement.execute(JtdsStatement.java:1114)
at sjsql.execute(sjsql.java:385)
at sjsql.process(sjsql.java:293)
at sjsql.nonStaticMain(sjsql.java:220)
at sjsql.main(sjsql.java:76)
[sjsql] Errors occurred - changes rolled back
[sjsql] Errors occurred - exiting, start next run from line 65001 using the argument --start 65001
In this case, use a smaller batch size, or provide java with more memory by putting a memory argument directly after the java command. For example -Xmx256m will provide 256mb.
Your data is still safe, and committed to line 65000. In the error above, the tool is instructing you how to start the next batch from line 65001, using the --start parameter.
| sjsql.class | ![]() |
9701 bytes |
| sjsql.java | ![]() |
13659 bytes |