Running Oracle SQL / Call URL

The following program was whipped together to pre-cache pages on our server by hitting them with an HTTP request based on a query.

Running a SQL query and calling that URL like Curl to precache results


#!/usr/bin/env groovy
//
// Groovy Script to call each gene page in turn
// Requirements : Drop the Oracle jdbc14.jar driver in your $HOME/.groovy/lib directory then run this script
//
import groovy.sql.Sql

println "Started"
sql = Sql.newInstance("jdbc:oracle:thin:@server.com:1521:SID", "USERID", "password", "oracle.jdbc.driver.OracleDriver");

sql.eachRow("select * from genes, rgd_ids where genes.rgd_id = rgd_ids.rgd_id and rgd_ids.object_status = 'ACTIVE' and rgd_ids.species_type_key = 3", {
println "Calling: http://rgd.mcw.edu/tools/genes/genes_view.cgi?id=${it.rgd_id}"
// creates a new URL obect and downloads that HTML into the contents variable
def contents = new URL("http://rgd.mcw.edu/tools/genes/genes_view.cgi?id=${it.rgd_id}").getText()
// Uncomment next line to print contents of page
// println contents
}
)
println "Done"
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s