Skip to content

Instantly share code, notes, and snippets.

@lyhcode
Created January 10, 2012 13:50
Show Gist options
  • Save lyhcode/1589174 to your computer and use it in GitHub Desktop.
Save lyhcode/1589174 to your computer and use it in GitHub Desktop.
sql server load test using groovy
@GrabConfig(systemClassLoader=true)
@Grab(group='net.sourceforge.jtds', module='jtds', version='1.2.4')
import groovy.sql.Sql
sql = Sql.newInstance( 'jdbc:jtds:sqlserver://localhost/test', 'sa',
'sasasa', 'net.sourceforge.jtds.jdbc.Driver' )
//sql.eachRow( 'select * from test1' ) { println "$it.id -- ${it.rnd} --" }
sql.execute('delete from test1');
begin = new Date()
for (i = 0; i < 1000000; i++) {
random = new Random(new Date().time)
sql.execute('insert into test1 (rnd, data) values(?,?)', ["${random.nextInt(199)+100}${random.nextInt(199)+100}${random.nextInt(199)+100}".toString(), new Date().time])
}
println(new Date().time - begin.time)
sql.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment