import java.sql.*;
import java.io.*;
import java.lang.*;
import java.awt.*;
public class filesave{
public static void main(String args[]){
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:mydb","sa","");
Statement stmt=con.createStatement();
//建立Statement对象
File str=new File("c://bbb.xls");
int fileLength = (int)str.length();
InputStream a= new FileInputStream(str);
String sql="insert into testfile(id,testfile) values('1',?)";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setBinaryStream (1, a, fileLength);
//pstmt.setBinaryStream (1, a,a.available());
pstmt.executeUpdate();
pstmt.close();
con.close();
}
catch(Exception e){System.out.print(e);}
}
}