写大对象。
Java code
public static void main(String[] args) {
// TODO Auto-generated method stub
Connection conn = null
Statement stat = null
ResultSet rs = null
OutputStream os = null
FileInputStream fis = null
int bs = 0
try {
Class.forName("oracle.jdbc.driver.OracleDriver")
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:oraDB","汪悄没bigfou","---")
conn.setAutoCommit(false)
stat = conn.createStatement()
stat.executeUpdate("insert into t_video(id,video) values(1,empty_blob())")
rs = stat.executeQuery("select video from t_video where id = 1")
rs.next()
oracle.sql.BLOB blo = (oracle.sql.BLOB)rs.getBlob(1)
os = blo.getBinaryOutputStream()
bs = blo.getBufferSize()
fis = new FileInputStream("D:\\Temp\\MPlayer-CVS-20040808-K&K\\运镇mplayer.exe")
byte[] buf = new byte[bs]
int length = 0
while(true)
{
length = fis.read(buf)
if(length == -1) break
os.write(buf,0,length)
}
os.close()
os = null
fis.close()
fis = null
conn.commit()
conn.setAutoCommit(true)
conn.close()
} catch(Exception ex) {
ex.printStackTrace()
}
}
读大对象
Java code
InputStream is = null
FileOutputStream fos = null
byte[] buf = null
int bs = 0
try {
Class.forName("oracle.jdbc.driver.OracleDriver")
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:oraDB","bigfou","-")
conn.setAutoCommit(false)
stat = conn.createStatement()
rs = stat.executeQuery("select video from t_video where id = 1")
rs.next()
oracle.sql.BLOB blo = (oracle.sql.BLOB)rs.getBlob(1)
bs = blo.getBufferSize()
buf = new byte[bs]
int length = 0
is = blo.getBinaryStream()
fos = new FileOutputStream("d:\\test.exe")
while(true) {
length = is.read(buf)
if(length == -1) break
fos.write(buf,0,length)
}
fos.close()
fos = null
is.close()
is = null
conn.commit()
conn.setAutoCommit(true)
conn.close()
...
默认情况下数据文件 *.dbf
控制文件 *.ctl
日志文件 *.log
参兆闷数文件 *.ora
跟尘陆踪文件族兄弯 *.trc
警告文件 *.log
exp文件 *.dmp
create table test(
NID VARCHAR2(1) not null,
IMG BLOB,
zhengqueFlag VARCHAR2(1),
cuowuFlag VARCHAR2(1)
)
说明:
1、IMG字段只需要保存图片,将图片信息经过Base64编码,存到数据库BLOB字段中。显示的时候要经态耐过Base64解码。
2、对于像“正确”、“错误”用标志位在区别。你可以用1表示正确、0表示错误。当然你也可以用汉字的保存这样腔闭碰的信息。自己来设计。
然后你到网上查一下怎么样对BLOB字伍谈段进行 *** 作。如果不行,我在增加回复。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)