Skip to content

Instantly share code, notes, and snippets.

@melastmohican
Created May 18, 2017 06:27
Show Gist options
  • Select an option

  • Save melastmohican/0a678fcfa04e357414dd4bf7ba7b01ad to your computer and use it in GitHub Desktop.

Select an option

Save melastmohican/0a678fcfa04e357414dd4bf7ba7b01ad to your computer and use it in GitHub Desktop.
Dump CSV using H2 CSV tools
#!/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