JDBC如何操作long/long raw/blob/clob数据类型

JDBC如何操作long/long raw/blob/clob数据类型
 
 
如何写long和long raw类型
          
          
quote:


case Types.LONGVARCHAR:
java.io.StringReader long_var =
new java.io.StringReader(oldval.toString());
stmt.setCharacterStream(pos,long_var,32768);
return;
case Types.LONGVARBINARY:
java.io.File os_file = new java.io.File(oldval.toString());
if (os_file.exists() && os_file.isFile() && os_file.canRead())
{
try {
java.io.FileInputStream long_bin =
new java.io.FileInputStream(os_file);
stmt.setBinaryStream(pos,long_bin,(int)(os_file.length()));
} catch (java.io.IOException ioe) {}
}
else
stmt.setNull(pos,1);
return;


 
 
如何操作BLOB/CLOB类型
============================
操作blob/clob时,先用select lobfld from tab where ... for update,取得java.sql.Blob或javq.sql.Clob类型

           
           

quote:



stmt
= prepareStatement(Database,p_query,variable_table);
stmt.bind(variable_table);
rset = stmt.stmt.executeQuery();
java.sql.ResultSetMetaData rsetmeta = rset.getMetaData();
if (rset.next())
{
if (rsetmeta.getColumnType(1) == java.sql.Types.CLOB)
{
java.sql.Clob clob = rset.getClob(1);
long offs = 0;
if (clob != null)
{
char[] long_buf=new char[8192];
try {
int len=0;
clob.truncate(offs);
java.io.Writer long_out = clob.setCharacterStream(0);
java.io.FileReader long_file = new java.io.FileReader(os_file);
while((len = long_file.read(long_buf))>0)
{
long_out.write(long_buf,0,len);
offs = offs + len;
}
long_file.close();
long_out.close();
}
catch ( java.io.IOException ioe)
{
log.println(ioe.getMessage());
}
}
}
else if (rsetmeta.getColumnType(1) == java.sql.Types.BLOB)
{
java.sql.Blob blob = rset.getBlob(1);
if (blob != null)
{
byte[] long_buf=new byte[8192];
long offs = 0;
try {
int len=0;
blob.truncate(offs);
java.io.OutputStream long_out = blob.setBinaryStream(0);
java.io.FileInputStream long_file = new java.io.FileInputStream(os_file);
while((len = long_file.read(long_buf))>0)
{
long_out.write(long_buf,0,len);
offs = offs + len;
}
long_file.close();
long_out.close();
}
catch ( java.io.IOException ioe)
{
log.println(ioe.getMessage());
}
}
}
data = getMessage(jdbc_cfg,"JDBC.COMMAND.COMPLETED");
log.println(data.getColumn(1));
}
else
{
log.println("0 "+jdbc_cfg.getNLSString("JDBC.COMMAND.ROWSSELECTED"));
}
}


 
 
如何读取long/longraw/blob/clob中的数据?
            
            

quote:



stmt
= prepareStatement(Database,p_query,variable_table);
stmt.bind(variable_table);
rset = stmt.stmt.executeQuery();
java.sql.ResultSetMetaData rsetmeta = rset.getMetaData();
if (rset.next())
{
if (rsetmeta.getColumnType(1) == java.sql.Types.LONGVARCHAR)
{
java.io.Reader long_out = rset.getCharacterStream(1);
if (long_out != null)
{
char[] long_buf=new char[8192];
try {
int len=0;
java.io.FileWriter long_file = new java.io.FileWriter(os_file);
while((len = long_out.read(long_buf))>0)
long_file.write(long_buf,0,len);
long_file.close();
long_out.close();
}
catch ( java.io.IOException ioe)
{
log.println(ioe.getMessage());
}
}
}
else if (rsetmeta.getColumnType(1) == java.sql.Types.LONGVARBINARY)
{
java.io.InputStream long_out = rset.getBinaryStream(1);
if (long_out != null)
{
byte[] long_buf=new byte[8192];
try {
int len=0;
java.io.FileOutputStream long_file = new java.io.FileOutputStream(os_file);
while((len = long_out.read(long_buf))>0)
long_file.write(long_buf,0,len);
long_file.close();
long_out.close();
}
catch ( java.io.IOException ioe)
{
log.println(ioe.getMessage());
}
}
}
else if (rsetmeta.getColumnType(1) == java.sql.Types.CLOB)
{
java.sql.Clob clob = rset.getClob(1);
if (clob != null)
{
java.io.Reader long_out = clob.getCharacterStream();
if (long_out != null)
{
char[] long_buf=new char[8192];
try {
int len=0;
java.io.FileWriter long_file = new java.io.FileWriter(os_file);
while((len = long_out.read(long_buf))>0)
long_file.write(long_buf,0,len);
long_file.close();
long_out.close();
}
catch ( java.io.IOException ioe)
{
log.println(ioe.getMessage());
}
}
}
}
else if (rsetmeta.getColumnType(1) == java.sql.Types.BLOB)
{
java.sql.Blob blob = rset.getBlob(1);
if (blob != null)
{
java.io.InputStream long_out = blob.getBinaryStream();
if (long_out != null)
{
byte[] long_buf=new byte[8192];
try {
int len=0;
java.io.FileOutputStream long_file = new java.io.FileOutputStream(os_file);
while((len = long_out.read(long_buf))>0)
long_file.write(long_buf,0,len);
long_file.close();
long_out.close();
}
catch ( java.io.IOException ioe)
{
log.println(ioe.getMessage());
}
}
}
}
data = getMessage(jdbc_cfg,"JDBC.COMMAND.COMPLETED");
log.println(data.getColumn(1));
}
else
{
log.println("0 "+jdbc_cfg.getNLSString("JDBC.COMMAND.ROWSSELECTED"));
}


 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值