代码:
try
{
java.sql.Connection c = o.getConnection () ;
java.sql.PreparedStatement pst = null ;
pst = c.prepareStatement (
"INSERT INTO sunmeng.DATATYPE_BLOB VALUES(?)" ) ;
//---
File f = new File ( "c:\\a.bmp" ) ;
int flen = ( int ) f.length () ;
FileInputStream fis = new FileInputStream ( f ) ;
pst.setBinaryStream ( 1 , fis , flen ) ;
pst.executeUpdate () ;
//----
pst.close () ;
o.close () ;
fis.close () ;
}报告:
toString:java.sql.SQLException: ORA-00600: 内部错误代码,自变量: [12204], [24], [], [], [], [], [], []
getMessage:ORA-00600: 内部错误代码,自变量: [12204], [24], [], [], [], [], [], []
try
{
java.sql.Connection c = o.getConnection () ;
java.sql.PreparedStatement pst = null ;
pst = c.prepareStatement (
"INSERT INTO sunmeng.DATATYPE_BLOB VALUES(?)" ) ;
//---
File f = new File ( "c:\\a.bmp" ) ;
int flen = ( int ) f.length () ;
FileInputStream fis = new FileInputStream ( f ) ;
pst.setBinaryStream ( 1 , fis , flen ) ;
pst.executeUpdate () ;
//----
pst.close () ;
o.close () ;
fis.close () ;
}报告:
toString:java.sql.SQLException: ORA-00600: 内部错误代码,自变量: [12204], [24], [], [], [], [], [], []
getMessage:ORA-00600: 内部错误代码,自变量: [12204], [24], [], [], [], [], [], []
解决方案 »
- JDBC不能创建触发器?
- 关于java.lang.Runtime().exec()的问题?
- 线程重启动问题
- 讨论:在JDK1.5,StringBuffer比String有多大优势?,String 与 StringBuffer类
- jni应用,在unix如何寻找动态链接库,急!!!
- 请问用JAVA做QQ这样的程序要用到什么技术?在线等(急)
- 关于MouseMotionListener
- 在JB中,怎么做组件可能以使之放在JB中的组件面板上?
- 反编java
- 各位,请问一下,我在第一运行JBuilder的时候,它向我要Login name和password应该怎么输入呀?
- 包的困惑
- 请问在Solaris下如何访问access数据库?
oracle.sql.BLOB ablob = new oracle.sql.BLOB();
fis.readBytes(content)
ablob.setBytes(0,content);
pst.setBlob(ablob); 你可以试试看。
"BlobUtil.java": cannot find symbol; symbol : constructor BLOB(java.sql.Connection,byte[]), location: class oracle.sql.BLOB at line 107, column 34
int flen = ( int ) f.length () ;
FileInputStream fis = new FileInputStream ( f ) ;
byte[] content = new byte[flen];
fis.read(content);
oracle.sql.BLOB ablob = oracle.sql.BLOB.empty_lob();
ablob.setBytes(content);这样试试。。至少测试没有错误 :)
import java.sql.*;
public class BlobOperation
{
public static void addLob(long id, String binFile) throws SQLException
{
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null; try
{
con = ConnectionFactory.getConnection(); //换成你自己取连接的方法
con.setAutoCommit(false); String sql = "INSERT INTO Blob_Tbl(id, binfile, bincontent)";
sql += " VALUES(?, ?, ?)";
ps = con.prepareStatement(sql); ps.setLong(1, id);
ps.setString(2, binFile);
ps.setBlob(3, oracle.sql.BLOB.empty_lob()); ps.executeUpdate();
//DatabaseUtils.closeObject(ps); ps = con.prepareStatement("SELECT bincontent FROM Blob_Tbl WHERE id = " + id + " for update ");
rs = ps.executeQuery(); if (rs.next())
{
oracle.sql.BLOB binContent = (oracle.sql.BLOB) rs.getBlob(1); /* write blob content */
OutputStream binOut = binContent.getBinaryOutputStream();
BufferedOutputStream out = new BufferedOutputStream(binOut);
BufferedInputStream in = new BufferedInputStream(new FileInputStream(binFile));
int c;
while ((c = in.read()) != -1)
{
out.write(c);
}
in.close();
out.close();
}
con.commit();
} catch (Exception e)
{
e.printStackTrace();
try
{
con.rollback();
} catch (SQLException se)
{
}
throw new SQLException(e.getMessage());
} finally
{
DatabaseUtils.closeObject(rs, ps, con);
}
} public static void fetchLob(long id, String filename) throws SQLException
{
Connection con = null;
Statement st = null;
ResultSet rs = null; try
{
con = ConnectionFactory.getConnection(); String sql = "SELECT * From Blob_Tbl Where id = " + id;
st = con.createStatement(); rs = st.executeQuery(sql);
while (rs.next())
{ String binFile = rs.getString("binfile");
oracle.sql.BLOB binContent = (oracle.sql.BLOB) rs.getBlob("bincontent"); /* read blob content */
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(filename));
BufferedInputStream in = new BufferedInputStream(binContent.getBinaryStream()); int c;
while ((c = in.read()) != -1)
{
out.write(c);
}
in.close();
out.close();
} } catch (Exception e)
{
throw new SQLException(e.getMessage());
} finally
{
DatabaseUtils.closeObject(rs, st, con);
}
} public static void main(String[] args) throws Exception
{
if (args.length == 0)
{
addLob(1, "a.jpg");
} else
{
fetchLob(1, args[0]);
}
}
}
我的oracle.sql.BLOB没有 empty_lob () 这个函数!
建议下载 ORACLE 9I 的 JDBC!!
我的有!!
您好!请问您 ORACLE 9I 的 JDBC在那里下载!