Created
May 18, 2017 06:27
-
-
Save melastmohican/0a678fcfa04e357414dd4bf7ba7b01ad to your computer and use it in GitHub Desktop.
Dump CSV using H2 CSV tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env groovy | |
| @Grapes([ | |
| @Grab(group = 'com.h2database', module = 'h2', version = '1.4.194'), | |
| @GrabConfig(systemClassLoader=true) | |
| ]) | |
| import java.sql.*; | |
| import org.h2.tools.Csv; | |
| def dumpCSV() { | |
| def csvFile = "bel/bel_reaction_data.txt" | |
| def csv = new Csv() | |
| csv.setFieldDelimiter('\t' as char) | |
| ResultSet rs = csv.read(csvFile, null, null) | |
| ResultSetMetaData meta = rs.getMetaData() | |
| while (rs.next()) { | |
| for (int i = 0; i < meta.getColumnCount(); i++) { | |
| println meta.getColumnLabel(i + 1) + ": " + rs.getString(i + 1) | |
| } | |
| println '' | |
| } | |
| rs.close() | |
| } | |
| dumpCSV() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment