---
title: "Groovy之连接数据库"
author: "VerRan"
date: "2010-07-19T16:54:33Z"
tags: ["Groovy", "JDBC", "Oracle", "SQL"]
categories: ["企业架构"]
slug: "groovy"
draft: false
lastmod: "2010-07-22T16:46:15Z"
id: 716252
url: "https://verran.iteye.com/blog/716252"
---

让我们远离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)");


```