版本:groovy 2.2
API:JDBC/GroovySQL
package DbUtil_Shield
import groovy.sql.Sql
import java.sql.Connection;
import net.sourceforge.jtds.jdbc.Driver
/**
*
* @author Administrator
*/
class DefaultGroovySqlDbUtil {
def url="localhost";
def user="sa";
def password="sa";
def port=8087;
def dbName="shiled";
Sql getGroovySql(){
def sql=Sql.newInstance("jdbc:jtds:sqlserver://localhost:4512/dbxxx"sa","sa","net.sourceforge.jtds.jdbc.Driver");
def sql_id_list="select id from v_products where ctid=65535 and is_auditing=1 and trueeship='0' and subsite_auditing='1'"
sql.eachRow(sql_id_list){
row ->
println "${ row.id}"
}
}
static void main(argvs){
def dbutil=new DefaultGroovySqlDbUtil();
println dbutil.getUser();
dbutil.getGroovySql();
}
}
官方文档:
groovy.sql
Class Sql
java.lang.Object
groovy.sql.Sql
Direct Known Subclasses:
DataSet
public class Sql
extends Object
A facade over Java's normal JDBC APIs providing greatly simplified resource management and result set handling. Under the covers the facade hides away details associated with getting connections, constructing and configuring statements, interacting with the connection, closing resources and logging errors. Spe