其他
Java教程-在Oracle数据库中存储图像的示例
setBinaryStream方法的签名
setBinaryStream()方法的语法如下:
1) public void setBinaryStream(int paramIndex, InputStream stream)
throws SQLException
2) public void setBinaryStream(int paramIndex, InputStream stream, long length)
throws SQLException
CREATE TABLE "IMGTABLE"
( "NAME" VARCHAR2(4000),
"PHOTO" BLOB
)
/
专属福利
在数据库中存储图像的Java示例
import java.sql.*;
import java.io.*;
public class InsertImage {
public static void main(String[] args) {
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
PreparedStatement ps=con.prepareStatement("insert into imgtable values(?,?)");
ps.setString(1,"sonoo");
FileInputStream fin=new FileInputStream("d:\g.jpg");
ps.setBinaryStream(2,fin,fin.available());
int i=ps.executeUpdate();
System.out.println(i+" records affected");
con.close();
}catch (Exception e) {e.printStackTrace();}
}
}
我就知道你会点赞+“在看”