📄 test2.java
字号:
package com.prodb;
import java.io.*;
import java.sql.*;
public class Test2 {
private ResultSet rs;
private Statement stmt;
private Connection con;
private PrintWriter out;
private Blob blob;
public void addBlob(String fileName) throws Exception{
con=Test1.getCon();
con.setAutoCommit(false);
stmt=con.createStatement();
// stmt.execute("INSERT INTO Test1(data) VALUES (NULL)");
rs=stmt.executeQuery("SELECT data FROM Test1 ");
while(rs.next()){
try{
blob=rs.getBlob(1);
}catch(Exception e){
out.print(e);
}
InputStream bin=blob.getBinaryStream();
// System.out.println(blob);
System.out.println(blob.length());
}
rs.close();
stmt.close();
con.close();
/*File binaryFile=new File(fileName);
System.out.println(fileName+"的长度="+binaryFile.length());
FileInputStream instream=new FileInputStream(binaryFile);
OutputStream outstream=null;
int chunk=0;
byte[] buffer=new byte[chunk];
int length=-1;
while((length=instream.read(buffer))!=-1){
outstream.write(buffer,0,length);
instream.close();
outstream.close();
con.commit();
}*/
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -