import java.io.*;
import java.util.*;
import java.sql.*;
import oracle.jdbc.driver.*;
import java.text.*;
public class test
{
public static void main(String args[]) throws java.io.IOException,java.sql.SQLException
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch (java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: " + e.getMessage());
}
try
{
File files = new File("c://test.xls");
FileInputStream fis=new FileInputStream(files);
System.out.println(files.getName());
System.out.println((int)files.length());
byte[] fl = new byte[(int)files.length()];
System.out.println(fl.length);
fis.read(fl);
ByteArrayInputStream kk = new ByteArrayInputStream(fl) ;
Connection conn = DriverManager.getConnection("jdbc
racle:thin
eaiserver01:1521
rcl", "system", "admin");
PreparedStatement ps = conn.prepareStatement("INSERT INTO bin_data (name,data)" +"VALUES (?, ?)");
ps.setString(1,files.getName());
ps.setBinaryStream(2, kk,(int)files.length());
ps.executeUpdate();
fis.close();
ps.close();
int bytesRead = 0;
int byteSum = 0;
byte[] buffer = new byte[8 * 1924];
FileOutputStream fis2 = new FileOutputStream("c://hi.xls");
PreparedStatement ps2 = conn.prepareStatement( "select data from bin_data");
ResultSet rs = ps2.executeQuery();
if (rs != null)
{
while(rs.next())
{
InputStream is = rs.getBinaryStream(1);
while ((bytesRead = is.read(buffer)) != -1)
{
byteSum += bytesRead;
fis2.write(buffer, 0, bytesRead);
}
fis2.close( );
}
rs.close( );
}
ps2.close( );
}
catch(Exception e)
{
System.out.println("errror :"+e.toString() );
e.printStackTrace();
}
}
}