Jon Aquino's Mental Garden

Engineering beautiful software jon aquino labs | personal blog

Friday, July 16, 2004

Just wanted to share this example of Groovy code, which creates a text file from an Oracle table.
 import groovy.sql.Sql

import java.io.File

x = Sql.newInstance("jdbc:oracle:thin:@x:1521:x", "x", "x", "oracle.jdbc.driver.OracleDriver")
try {
new File("sql.txt").withWriter() { writer |
x.eachRow('select * from veg_label') { row |
writer.writeLine(row.object_version_skey+"")
}
}
}
finally {
x.close()
}
Groovy is a scripting language that runs on top of Java (i.e. you can access Log4J, JUnit, or any other jar). The great thing about Groovy is its brevity -- compare to what you would need to do in regular verbose Java.

More info on the coolness of Groovy: http://www.iraqilinux.org/modules.php?name=Forums&file=viewtopic&p=739

0 Comments:

Post a Comment

<< Home