groovy select with metadata


/ Published in: Groovy
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.