Brian's Waste of Time

Fri, 20 Feb 2004

Better GroovySQL Example

Glen complained that the example in my previous post was pretty bad, so here is a better one in honor of Andy ;-)

<step name="md5-passwords" type="groovy">
    <script>
import groovy.sql.Sql
import java.security.MessageDigest

sql = new Sql(connection)

sql.queryEach("select password, user_id from users") {
    MessageDigest md = MessageDigest.getInstance("MD5")
    sql.execute("update users set password=? where user_id=?",
                 [md.digest(it.password.bytes), it.user_id])
}
    </script>
</step>

=)

4 writebacks [/src/groovy] permanent link