Groovy连接数据并打印数据(3),超简单!

import groovy.sql.Sql

def q_id = 22
def sql = Sql.newInstance("jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.41)(PORT = 1521)))(CONNECT_DATA =(SID = syntong)))","auto","auto_123","oracle.jdbc.driver.OracleDriver")

sql.eachRow("select * from role where id=${q_id}"){
println "Name is ${it.name}"
}


运行方法:使用EditPlus,设置方法如下:
Groovy连接数据并打印数据(3),超简单!

运行结果:

---------- 运行GroovyScript ----------
Name is 车辆审批领导

输出完毕 (耗时 8 秒) - 正常终止

你可能感兴趣的:(oracle,sql,jdbc,groovy)