(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. Ubuntu 16.04安装搜狗输入法

    转载: http://www.it610.com/article/5319575.htm 打开firefox浏览器,输入网址www.baidu.com,打开后搜索搜狗拼音 linux进入到搜狗拼音li ...

  2. 插件dTree的使用

    解压缩dtree.zip 包.  dtree目录下包括这些文件:example01.html . dtree.js . api.html . dtree.css 和img目录       注意:除了a ...

  3. 深入学习 celery

    一.amqp交换 参考链接: http://www.cnblogs.com/ajianbeyourself/p/4950758.html

  4. TCP/IP协议学习(四) 基于C# Socket的Web服务器---静态资源处理

    目录 1. C# Socket通讯 2. HTTP 解析引擎 3. 资源读取和返回 4. 服务器测试和代码下载 Web服务器是Web资源的宿主,它需要处理用户端浏览器的请求,并指定对应的Web资源返回 ...

  5. Sudoku 数独游戏

    #include<iostream> using namespace std; bool heng(int **sudo, int a, int b, int value) { bool ...

  6. Table 'performance_schema.session_variables' doesn't exist

    出现标题所示错误时设置如下参数可以解决!set @@global.show_compatibility_56=ON;

  7. 配置handler vs2013 iis8.0

    <system.webServer> <modules runAllManagedModulesForAllRequests="true" /> <v ...

  8. 修改mysql密码

    方法1: 用SET PASSWORD命令首先登录MySQL.格式:mysql> set password for 用户名@localhost = password('新密码');例子:mysql ...

  9. 添加as源码

    http://blog.csdn.net/zhang31jian/article/details/23258065

  10. Js实现简单的洗牌

    基础篇 洗牌采用的是,每一张牌,与后面随机一张牌来交换位置. 扑克牌采用编码制(如,0代表红桃A,依次类推)为了编码方便,扑克牌不含大小王,故52张. 一.扑克牌的了解 扑克(英文:Poker) 一副 ...