(1)jdbc执行预处理

PreparedStatment预备语句

eg:String sql="insert into user(id,name,birthday,money) values(5,'administrator',?,'1000000')";

PreparedStatement stmt=conn.prepareStatment(sql);

stmt.setTimestamp(1,new Timestamp(System.currentTimeMillis()));

stmt.execute();

(2)调用存储过程

对于标量函数 其调用字符串为{fn functionname(?,?)}/{fn functionname()}

对于存储过程 其调用字符串为{call proc(?,?)}/{call proc}/{call ?=proc(?,?)}

CallableStatement

无参数,无返回值的存储过程

String sql="{call test1()}";

CallableStatment stmt=conn.prepareCall(sql);

stmt.executeUpdate();

有参数,有返回值的存储过程

String sql="{call ?=test1(?)}";    //方式1

CallableStatment stmt=conn.prepareCall(sql);

stmt.setString(2,"test");

stmt.registerOutParameter(1,Type.Interger);

stmt.execute();

int result=stmt.getInt(1);

String sql="{call test1(?,?)}";    //方式2

CallableStatment stmt=conn.prepareCall(sql);

stmt.setString(1,"test");

stmt.registerOutParameter(2,Type.Interger);

stmt.execute();

int result=stmt.getInt(2);

(3)jdbc数据批处理

String sql="insert into user(id,name,birthday,money) values(?,?,?,?)";

PreparedStatement stmt=conn.prepareStatement(sql);

for (int i=1;i<1000;i++){

stmt.setInt(1,i);

stmt.setString(2,"test");

stmt.setDate(3,new Date(System.currentTimeMillis()));

stmt.setFloat(4,1000);

stmt.addBatch(sql);

}

int[] result=stmt.executeBatch();

(4)LOB字段(BLOB,CLOB)处理

处理常用类与方法

java.sql.ResultSet

Blob getBlob(int columnIndex);

Blob getBlob(string columnLabel);

Clob getClob(int columnIndex);

Clob getClob(string columnLabel);

-----------------------------------------------------------------

java.sql.Blob

long length();

byte[] getBytes(long startPosition,long length);

InputStream getBinaryStream();

InputStream getBinaryStream(long startPosition,long length);

OutputStream setBinaryStream(long startPosition);

java.sql.Clob

long length();

byte[] getSubString(long startPosition,long length);

Reader getCharacterStream();

Reader getCharacterStream(long startPosition,long length);

Writer setCharacterStream(long startPosition);

-----------------------------------------------------------------

java.sql.Connection

Blob createBlob();

Clob createClob();

----------------------------------------------------------------

eg:

PreparedStament stmt=conn.prepareStatement("select pic from book where bokkid='1'");

ResultSet rt=stmt.executeQuery();

if(rt.next()){

Blob blob=rt.getBlob(1);

Image img=ImageIO.read(blob.getInputStream());

}

--------------------------------------------------------------------------------------------

Blob blob=conn.createBlob();

int offset=0;

OutputStream out=blob.setBinaryStream(offset);

ImageIO.write(img,"PNG",out);

PreparedStament stmt=conn.prepareStatement("insert into book values(?,?)");

stmt.setInt(1,1);

stmt.setBlob(2,blob);

stmt.executeUpdate();

--------------------------------------------------------------------------------------------

PreparedStament stmt=conn.prepareStatement("insert into book values(?,?)");

stmt.setInt(1,1);

File file=new File("E:\\text.txt");

FileReader reader=new FileReader(file);

BufferReader buffer=new BufferReader(reader);

stmt.setCharacterStream(2,buffer,3);

stmt.execute();

--------------------------------------------------------------------------------------------

PreparedStament stmt=conn.prepareStatement("select pic from book where id=1");

ResuleSet rs=stmt.exexcuteQuery();

if(rs.next()){

  String strTmp="";

Reader read=rs.getCharacterStream(1);

BufferReader br=new BufferReader(read);

File file=new File("E:\\text.txt");

FileWriter fw=new FileWriter(f);

BufferWriter bw=new BufferWriter(fw);

while((strTmp=br.readLine())!=null){

bw.writer(strTmp+"\n");

bw.flush();

}

bw.close();

fw.close();

br.close();

}

jdbc执行预处理,批处理,LOB字段处理,调用存储过程的更多相关文章

  1. ASP调用存储过程访问SQL Server

     ASP调用存储过程访问SQL Server 2011-02-15 10:22:57 标签:asp 数据库 sQL 存储过程 Server ASP和存储过程(Stored Procedures)的文章 ...

  2. JDBC第二篇--【PreparedStatment、批处理、处理二进制、自动主键、调用存储过程、函数】

    这是我JDBC的第一篇 http://blog.csdn.net/hon_3y/article/details/53535798 1.PreparedStatement对象 PreparedState ...

  3. JDBC【PreparedStatment、批处理、处理二进制、自动主键、调用存储过程、函数】

    1.PreparedStatement对象 PreparedStatement对象继承Statement对象,它比Statement对象更强大,使用起来更简单 Statement对象编译SQL语句时, ...

  4. 【转载】JDBC操作LOB字段

    转自:http://www.cnblogs.com/tengtao93/p/4984689.html 1.LOB(Large Objects)大对象,是用来存储大量的二进制和文本数据的一种数据类型(一 ...

  5. JDBC 学习笔记(二)—— 大数据+存储过程+批处理+事务管理

    本文目录:       1.使用JDBC处理大数据        2.使用JDBC处理大文本        3.使用JDBC处理二进制数据        4.Oracle中大数据处理        5 ...

  6. Java数据库连接——JDBC调用存储过程,事务管理和高级应用

    一.JDBC常用的API深入详解及存储过程的调用 相关链接:Jdbc调用存储过程 1.存储过程(Stored Procedure)的介绍 我们常用的操作数据库语言SQL语句在执行的时候需要先编译,然后 ...

  7. Java数据库连接--JDBC调用存储过程,事务管理和高级应用

    相关链接:Jdbc调用存储过程 一.JDBC常用的API深入详解及存储过程的调用 1.存储过程的介绍 我们常用的操作数据库语言SQL语句在执行的时候要先进行编译,然后执行,而存储过程是在大型数据库系统 ...

  8. 【Java EE 学习 29 下】【JDBC编程中操作Oracle数据库】【调用存储过程的方法】

    疑问:怎样判断存储过程执行之后返回值是否为空. 一.连接oracle数据库 1.需要的jar包:在安装的oracle中就有,所以不需要到官网下载,我的oracle11g下:D:\app\kdyzm\p ...

  9. varchar2_to_blob,应用向数据库更新LOB字段时的超时问题

    将字符串转换为BLOB类型数据,写入服务器. 1,首先利用to_clob函数把varchar2字段转成 clob字段. 2  利用c2b上面函数将clob转成blob. 即: c2b(to_clob( ...

随机推荐

  1. jpg/png格式图片转eps格式的方法总结

    jpg/png格式图片转eps格式的方法总结 转自http://blog.sina.com.cn/s/blog_5410e7b50101lme2.html 用latex写论文的筒子应该遇到这样的问题: ...

  2. 在Ubuntu下使用 csapp.h 和 csapp.c

    它山之石可以攻玉. 对于<深入理解计算机系统>这本神人写就的神书, 我等凡人就不评论什么啦. 这本书的 第二,三 部分, 真的真的对我理解操作系统有很大的帮助. (当然, 如果你不看第一部 ...

  3. 用Excel制作热图(heatmap)的方法

    http://jingyan.baidu.com/article/64d05a0240ec75de55f73bd8.html 利用Excel 2010及以上版本的"条件格式"--& ...

  4. npm相关

    npm list -g --depth 0 : -g 列出所有全局模块,--depth 使列表只列出简略信息,如包名.版本号

  5. Linux时间设置及同步

    Linux系统安装时选择的UTC时间是国际标准时间,而中国处于UTC+8时区,因此安装系统时不要选择UTC时区. 还有就是Linux有两个时钟: 1.Bios时钟及硬件时间 2.Kernel时钟及系统 ...

  6. 慕课网__css_ float

  7. JS新API标准 地理定位(navigator.geolocation)

    在新的API标准中,可以通过navigator.geolocation来获取设备的当前位置,返回一个位置对象,用户可以从这个对象中得到一些经纬度的相关信息. navigator.geolocation ...

  8. PHP curl 实现RESTful PUT DELETE 实例

    PHP curl 实现RESTful PUT DELETE 实例 客户端 client.php <?php //PUT $curl_handle = curl_init ();// Set de ...

  9. jquery阻止元素冒泡的两种方法

    通常情况下,如果给父元素添加事件之后,子元素也会继承同样的事件,这个时候就要阻止子元素的这种行为,成为阻止冒泡,总结两种解决方法: html代码: <div id="parent&qu ...

  10. Python anaconda links to GOMP_4.0 and throws error

    ImportError: /usr/progtools/anaconda2/bin/../lib/libgomp.so.1: version `GOMP_4.0' not found (require ...