package my;
import java.io.*;
import java.sql.*;
public class LobPros
{
/**
* ORACLE驱动程序
*/
private static final String DRIVER = "net.sourceforge.jtds.jdbc.Driver";
/**
* ORACLE连接用URL
*/
private static final String URL = "jdbc:jtds:sybase://172.16.7.4:5000/ChargeInfo;charset=GBK";
/**
* 用户名
*/
private static final String USER = "sa";
/**
* 密码
*/
private static final String PASSWORD = "781216";
/**
* 数据库连接
*/
private static Connection conn = null;
/**
* SQL语句对象
*/
private static Statement stmt = null;
/**
* @roseuid 3EDA089E02BC
*/
public LobPros()
{
}
/**
* 往数据库中插入一个新的CLOB对象
*
* @param infile -
* 数据文件
* @throws java.lang.Exception
* @roseuid 3EDA04A902BC
*/
public static void clobInsert(String infile) throws Exception
{
/* 设定不自动提交 */
boolean defaultCommit = conn.getAutoCommit();
conn.setAutoCommit(false);
try {
/* 插入一个空的CLOB对象 */
stmt.executeUpdate("INSERT INTO TEST_CLOB VALUES (111, '')");
/* 查询此CLOB对象并锁定 */
ResultSet rs = stmt.executeQuery("SELECT post_text FROM TEST_CLOB WHERE post_id=111");
while (rs.next()) {
/* 取出此CLOB对象 */
net.sourceforge.jtds.jdbc.ClobImpl
/* 向CLOB对象中写入数据 */
BufferedWriter out = new BufferedWriter(clob.getCharacterOutputStream());
BufferedReader in = new BufferedReader(new FileReader(infile));
int c;
while ((c=in.read())!=-1) {
out.write(c);
}
in.close();
out.close();
}
/* 正式提交 */
conn.commit();
} catch (Exception ex) {
/* 出错回滚 */
conn.rollback();
throw ex;
}
/* 恢复原提交状态 */
conn.setAutoCommit(defaultCommit);
}
/**
* 修改CLOB对象(是在原CLOB对象基础上进行覆盖式的修改)
*
* @param infile -
* 数据文件
* @throws java.lang.Exception
* @roseuid 3EDA04B60367
*/
public static void clobModify(String infile) throws Exception
{
/* 设定不自动提交 */
boolean defaultCommit = conn.getAutoCommit();
conn.setAutoCommit(false);
try {
/* 查询CLOB对象并锁定 */
ResultSet rs = stmt.executeQuery("SELECT CLOBCOL FROM TEST_CLOB WHERE ID='111' FOR UPDATE");
while (rs.next()) {
/* 获取此CLOB对象 */
oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("CLOBCOL");
/* 进行覆盖式修改 */
BufferedWriter out = new BufferedWriter(clob.getCharacterOutputStream());
BufferedReader in = new BufferedReader(new FileReader(infile));
int c;
while ((c=in.read())!=-1) {
out.write(c);
}
in.close();
out.close();
}
/* 正式提交 */
conn.commit();
} catch (Exception ex) {
/* 出错回滚 */
conn.rollback();
throw ex;
}
/* 恢复原提交状态 */
conn.setAutoCommit(defaultCommit);
}
/**
* 替换CLOB对象(将原CLOB对象清除,换成一个全新的CLOB对象)
*
* @param infile -
* 数据文件
* @throws java.lang.Exception
* @roseuid 3EDA04BF01E1
*/
public static void clobReplace(String infile) throws Exception
{
/* 设定不自动提交 */
boolean defaultCommit = conn.getAutoCommit();
conn.setAutoCommit(false);
try {
/* 清空原CLOB对象 */
stmt.executeUpdate("UPDATE TEST_CLOB SET CLOBCOL=EMPTY_CLOB() WHERE ID='111'");
/* 查询CLOB对象并锁定 */
ResultSet rs = stmt.executeQuery("SELECT CLOBCOL FROM TEST_CLOB WHERE ID='111' FOR UPDATE");
while (rs.next()) {
/* 获取此CLOB对象 */
oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("CLOBCOL");
/* 更新数据 */
BufferedWriter out = new BufferedWriter(clob.getCharacterOutputStream());
BufferedReader in = new BufferedReader(new FileReader(infile));
int c;
while ((c=in.read())!=-1) {
out.write(c);
}
in.close();
out.close();
}
/* 正式提交 */
conn.commit();
} catch (Exception ex) {
/* 出错回滚 */
conn.rollback();
throw ex;
}
/* 恢复原提交状态 */
conn.setAutoCommit(defaultCommit);
}
/**
* CLOB对象读取
*
* @param outfile -
* 输出文件名
* @throws java.lang.Exception
* @roseuid 3EDA04D80116
*/
public static void clobRead(String outfile) throws Exception
{
/* 设定不自动提交 */
boolean defaultCommit = conn.getAutoCommit();
conn.setAutoCommit(false);
try {
/* 查询CLOB对象 */
ResultSet rs = stmt.executeQuery("SELECT * FROM TEST_CLOB WHERE ID='111'");
while (rs.next()) {
/* 获取CLOB对象 */
oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("CLOBCOL");
/* 以字符形式输出 */
BufferedReader in = new BufferedReader(clob.getCharacterStream());
BufferedWriter out = new BufferedWriter(new FileWriter(outfile));
int c;
while ((c=in.read())!=-1) {
out.write(c);
}
out.close();
in.close();
}
} catch (Exception ex) {
conn.rollback();
throw ex;
}
/* 恢复原提交状态 */
conn.setAutoCommit(defaultCommit);
}
/**
* 向数据库中插入一个新的BLOB对象
*
* @param infile -
* 数据文件
* @throws java.lang.Exception
* @roseuid 3EDA04E300F6
*/
public static void blobInsert(String infile) throws Exception
{
/* 设定不自动提交 */
boolean defaultCommit = conn.getAutoCommit();
conn.setAutoCommit(false);
try {
/* 插入一个空的BLOB对象 */
stmt.executeUpdate("INSERT INTO TEST_BLOB VALUES ('222', EMPTY_BLOB())");
/* 查询此BLOB对象并锁定 */
ResultSet rs = stmt.executeQuery("SELECT BLOBCOL FROM TEST_BLOB WHERE ID='222' FOR UPDATE");
while (rs.next()) {
/* 取出此BLOB对象 */
oracle.sql.BLOB blob = (oracle.sql.BLOB)rs.getBlob("BLOBCOL");
/* 向BLOB对象中写入数据 */
BufferedOutputStream out = new BufferedOutputStream(blob.getBinaryOutputStream());
BufferedInputStream in = new BufferedInputStream(new FileInputStream(infile));
int c;
while ((c=in.read())!=-1) {
out.write(c);
}
in.close();
out.close();
}
/* 正式提交 */
conn.commit();
} catch (Exception ex) {
/* 出错回滚 */
conn.rollback();
throw ex;
}
/* 恢复原提交状态 */
conn.setAutoCommit(defaultCommit);
}
/**
* 修改BLOB对象(是在原BLOB对象基础上进行覆盖式的修改)
*
* @param infile -
* 数据文件
* @throws java.lang.Exception
* @roseuid 3EDA04E90106
*/
public static void blobModify(String infi
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
java存lob数据到sybase.rar (37个子文件)
java存lob数据到sybase
spring+hibernate存lob数据
src
my
temp.jpg 19KB
IDAOService.java 1KB
PostDao.java 106B
users.hbm.xml 661B
Post.java 518B
BlobPros.java 3KB
HibernateDAO.java 123B
TestPostJdbcDao.java 2KB
TestFace.java 96B
LobPros.java 13KB
Test01.java 446B
PostJdbcDao.java 2KB
AbstractDAOService.java 2KB
config
hib-dao-cfg.xml 3KB
spring+jdbc存lob数据到sybase数据库
src
applicationContext.xml 921B
my
temp.jpg 19KB
PostDao.java 106B
users.hbm.xml 661B
Post.java 518B
TestPostJdbcDao.java 682B
Test01.java 516B
New Folder
PostJdbcDao.java 2KB
jdbc-dao-cfg.xml 9KB
config
jdbc-dao-cfg.xml 9KB
spring+hibernate,切面事务,存lob数据
src
my
temp.jpg 19KB
IDAOService.java 1KB
PostDao.java 106B
users.hbm.xml 646B
Post.java 518B
BlobPros.java 3KB
HibernateDAO.java 123B
TestPostJdbcDao.java 906B
TestFace.java 94B
Test01.java 453B
PostJdbcDao.java 2KB
AbstractDAOService.java 2KB
config
hib-dao-cfg.xml 3KB
共 37 条
- 1
hs0910
- 粉丝: 9
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1