Return to Snippet

Revision: 3152
at June 10, 2007 09:18 by thebugslayer


Updated Code
import groovy.sql.Sql

query = args[0]
sql = Sql.newInstance("jdbc:mysql://localhost:3306/mysql", "root", "", "com.mysql.jdbc.Driver")
sql.query(query){ rs ->
	while(rs.next()){	
		def meta = rs.metaData
		if(meta.columnCount <=0) return
		for(i in 1..meta.columnCount){
			print "${i}: ${meta.getColumnLabel(i)}".padRight(35)
			print rs.getObject(i)?.toString()
			print "\n"
		}
		println '-' * 70
	}
}

Revision: 3151
at June 10, 2007 09:18 by thebugslayer


Initial Code
import groovy.sql.Sql

query = args[0]
sql = Sql.newInstance("jdbc:mysql://localhost:3306/mysql", "root", "", "com.mysql.jdbc.Driver")

/*sql.query(query){ rs ->
	rs.next()
	println rs.getObject(1)	
}*/


sql.query(query){ rs ->
	while(rs.next()){	
		def meta = rs.metaData
		if(meta.columnCount <=0) return
		for(i in 1..meta.columnCount){
			print "${i}: ${meta.getColumnLabel(i)}".padRight(35)
			print rs.getObject(i)?.toString()
			print "\n"
		}
		println '-' * 70
	}
}

Initial URL

                                

Initial Description

                                

Initial Title
groovy select with metadata

Initial Tags

                                

Initial Language
Groovy