易截截图软件、单文件、免安装、纯绿色、仅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题 延伸二

 以下代码能否编译通过,如果不能,请说明理由,如果能,请说明结果。
public class a {

{
System.out.println("AAA");
}
a() {
System.out.println("BBB");
}
{
System.out.println("CCC");
}
class aa extends a {
{
new a();
System.out.prin ......

JAVA 之"线程"


1、进程与线程:
     《1》什么是进程:是指运行中的应用程序,每一个进程都有自己独立的内存空间,
          一个应用程序可以同时启动多个进程,(静态)比如(IE,JVM)
     《2》什么是线程:是指进程中的一个执行流程, ......

JAVA访问firebird数据库之Jaybird

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

WindowsMobile系统管理java插件

       WindowsMobile系统无法直接管理JAVA插件,需要借助JAVA虚拟机来管理JAVA插件,WM平台常见的JAVA虚拟机有Jbed和Jblend。下面就WM平台管理JAVA插件做简要介绍。
1、Jbed
Esmertec公司的产品,外部命令管理方式为:
安装:\Windows\jbed.exe -DFile.maxStorageSize=64M -ginstall \" ......

java与json的使用方式

  JSON 即 Java
Script Object Natation,它是一种轻量级的数据交换
格式,非常适合于服务器
与 Java
Script 的交互。本文将快速讲解 JSON 格式,并通过代码示例演示如何分别在客户端和服务器
端进行 JSON 格式数据的处理。
  Json必需的包
  commons-httpclient-3.1.jar
  commons-lang-2.4.jar
   ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号