We Recommend

Effective Tcl/Tk Programming: Writing Better Programs with Tcl and Tk Effective Tcl/Tk Programming: Writing Better Programs with Tcl and Tk
Shows how to build Tcl/Tk applications effectively. Teaches how to: create interactive displays with canvas widget, create customized editors with the text widget, handle data structures, interface with existing applications and more.


Posted By

thebugslayer on 06/10/07


Tagged


Versions (?)


groovy select with metadata


Published in: Groovy 


  1. import groovy.sql.Sql
  2.  
  3. query = args[0]
  4. sql = Sql.newInstance("jdbc:mysql://localhost:3306/mysql", "root", "", "com.mysql.jdbc.Driver")
  5. sql.query(query){ rs ->
  6. while(rs.next()){
  7. def meta = rs.metaData
  8. if(meta.columnCount <=0) return
  9. for(i in 1..meta.columnCount){
  10. print "${i}: ${meta.getColumnLabel(i)}".padRight(35)
  11. print rs.getObject(i)?.toString()
  12. print "\n"
  13. }
  14. println '-' * 70
  15. }
  16. }

Report this snippet 

You need to login to post a comment.