如何将图像存储到 Oracle 数据库中?以及如何从该数据库中检索图像?这是我的代码:
import java.io.*;
import java.sql.*;
import java.util.*;
class Pic3
{
public static void main(String args[]) throws Exception
{
Statement s;
Connection c;
FileInputStream fis;
PreparedStatement ps;
File file;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c=DriverManager.getConnection("Jdbc:Odbc:sidhu","system","system");
s=c.createStatement();
s.execute("Create table Img1(Image_No number(5),Photo blob)");
}
catch(Exception e1)
{
e1.printStackTrace();
}
try
{
file=new File("f:/image.jpeg");
fis=new FileInputStream(file);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c=DriverManager.getConnection("Jdbc:Odbc:sidhu","system","system");
String str="insert into Img1 values(?,?)";
ps=c.prepareStatement(str);
ps.setInt(1,(int)file.length());
ps.setBinaryStream(2,fis,(int)file.length());
//System.out.println("success");
ps.execute();
ps.close();
c.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}