ITeye博客

Groovy之连接数据库

VerRan · 2010-07-19 16:54 · Groovy · 企业架构 · Groovy · SQL · JDBC · Oracle · Markdown

让我们远离java丑陋的数据库连接吧

package dsl

import groovy.sql.Sql 
def orderCode="201003100621700";
db= Sql.newInstance( 
		"jdbc:oracle:thin:@127.0.0.1:CRM", 
		"iomcuser", 
		"iomcuser", 
		"oracle.jdbc.driver.OracleDriver") 
println("执行查询语句");
sysdate=db.firstRow ("select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual")
println sysdate[0];
orders=db.query ("select order_code,order_id from cust_order where order_code=$orderCode",{
	while(it.next()){
		println "order_code is "+it.getString("order_code");
		println "order_id is "+it.getString("order_id");
	}
})
println("执行修改类语句");
db.execute ("insert into enum_value values (100115,'93010314','警务E通','0','0','0','1','','-1','','','',null)");


评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。