易截截图软件、单文件、免安装、纯绿色、仅160KB

An agile dynamic language for the Java Platform

 Groovy supports a few neat ways to work with SQL more easily and to make SQL more Groovy. You can perform queries and SQL statements, passing in variables easily with proper handling of statements, connections and exception handling thanks to closures.
import groovy.sql.Sql
def foo = 'cheese'
def sql = Sql.newInstance("jdbc:mysql://localhost:3306/mydb", "user",
"pswd", "com.mysql.jdbc.Driver")
sql.eachRow("select * from FOOD where type=${foo}") {
println "Gromit likes ${it.name}"
}
In the above example, you can refer to the various columns by name, using the property syntax on the row variable (e.g. it.name) or you can refer to the columns by their index (e.g. it[0]) For example:
import groovy.sql.Sql
def foo = 'cheese'
def sql = Sql.newInstance("jdbc:mysql://localhost:3306/mydb", "user",
"pswd", "com.mysql.jdbc.Driver")
def answer = 0
sql.eachRow("select count(*) from FOOD where type=${foo}") { row ->
answer = row[0]
}
assert answer > 0
Or you can create a DataSet which allows you to query SQL using familar closure syntax so that the same query could work easily on in memory objects or via SQL. e.g.
import groovy.sql.Sql
def sql = Sql.newInstance("jdbc:mysql://localhost:3306/mydb", "user",
"pswd", "com.mysql.jdbc.Driver")
def food = sql.dataSet('FOOD')
def cheese = food.findAll { it.type == 'cheese' }
cheese.each { println "Eat ${it.name}" }
Advanced Usage
In this example, we create a table, make changes to it and confirm the changes worked.
def sql = Sql.newInstance("jdbc:mysql://localhost:3306/mydb",
"user", "pswd", "com.mysql.jdbc.Driver")
// delete table if previously created
try {
sql.execute("drop table PERSON")
} catch(Exception e){}
// create table
sql.execute('''create table PERSON (
id integer not null primary key,
firstname varchar(20),
lastname varchar(20),
location_id integer,
location_name varch


相关文档:

java入门

 Java学习从入门到精通 
一、 JDK (Java Development Kit) 
JDK是整个Java的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工具和Java基础的类库(rt.jar)。不论什么Java应用服务器实质都是内置了某个版本的JDK。因此掌握JDK是学好Java的第一步。最主流的J ......

Java NIO API详解

 
Java NIO API详解
在JDK
1.4以前,Java的IO操作集中在java.io这个包中,是基于流的阻塞(blocking)API。对于大多数应用来说,这样的API使用很方
便,然而,一些对性能要求较高的应用,尤其是服务端应用,往往需要一个更为有效的方式来处理IO。从JDK 1.4起,NIO
API作为一个基于缓冲区,并能提供非阻塞(non-blo ......

实战Java多线程编程不提倡做法

不提倡使用的方法是为支持向后兼容性而保留的那些方法,它们在以后的版本中可能出现,也可能不出现。Java 多线程支持在版本 1.1 和版本 1.2 中做了重大修订,stop()、suspend() 和 resume() 函数已不提倡使用。这些函数在 JVM 中可能引入微妙的错误。虽然函数名可能听起来很诱人,但请抵制诱惑不要使用它们。
调试线程化的 ......

JAVA访问firebird数据库之Jaybird

 
关于Jaybird-2.1.6JDK_1.5的使用方法如下:
首先:安装Jaybird
第一步:将根目录下的
       jaybird21.dll,
       GDS32.DLL,
       icudt30.dll,
       icuuc30.dll,
&nbs ......

java中涉及构造器的相关问题

            在看到Thinking in java 第四章时初始化相关问题的时候,我们不由地把注意力移到构造器上。这里做个简单的总结,便于高手指正以及自己温故。
      首先构造器是要构造一个东西{构造对象(实例)}并对其初始化。之所以 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号