Groovy 操作mysql数据库例子,Groovy 操作数据库
import groovy.sql.Sql
class MyGroovy {
static void main(args) {
def db_url="jdbc:mysql://localhost:3306/test"
def username="root"
def password="root"
def driverClass="com.mysql.jdbc.Driver"
def sql = Sql.newInstance(db_url, username, password, driverClass)
sql.eachRow("select * from dat"){row ->
println row.id
println row.path
def con ="un"
def path = "D://asd"
def pan = "E:"
sql.execute("insert into data_path (s_size, b_size, con,path,pan) values (1000, 10,${con}, ${path}, ${pan})")
}
}
}