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
相关文档:
1995年5月23日,Java语言诞生
1996年1月,第一个JDK-JDK1.0诞生
1996年4月,10个最主要的操作系统供应商申明将在其产品中嵌入JAVA技术
1996年9月,约8.3万个网页应用了JAVA技术来制作
1997年2月18日,JDK1.1发布
1997年4月2日,JavaOne会议召开,参与者逾一万人,创当时全球同类会议规模之纪录
1997年9 ......
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import sun.net.TelnetOutputStream;
import sun.net.TelnetInputStream;
import sun.net.ftp.FtpClient;
public class download ...{
& ......
这里,Java的读文件和写文件都是基于字符流的,主要用到下面的几个类:
1、FileReader----读取字符流
2、FileWriter----写入字符流
3、BufferedReader----缓冲指定文件的输入
该类的方法有:
void close()
关闭该流。
void mark(int readAhead ......
在oracle中调用java程序,注意:java方法必须是static类型的,如果想在JAVA中使用system.out/err输出log.
需要在oracle 中执行"call dbms_java.set_output(5000);".
一、helloWord
1 编写JAVA程序,也是在SQL/PLUS中写,并执行.
create or replace and compile java source named hello as
public ......
关于Jaybird-2.1.6JDK_1.5的使用方法如下:
首先:安装Jaybird
第一步:将根目录下的
jaybird21.dll,
GDS32.DLL,
icudt30.dll,
icuuc30.dll,
&nbs ......