日期:2014-05-20 浏览次数:20963 次
public static void write(File file) throws Exception{
		Class.forName("com.mysql.jdbc.Driver");
		Connection co=DriverManager.getConnection("jdbc:mysql://localhost:3306/abs","root","");
		String sql="insert into file (id,file) values (?,?)";
		PreparedStatement pst=co.prepareStatement(sql);
		pst.setInt(1, 1);
		InputStream in=new FileInputStream(file);
		pst.setBinaryStream(2, in, in.available());
		pst.executeUpdate();
		System.out.println("写入Ok!");
		in.close();
		pst.close();
		co.close();
	}
	public static void main(String[] args) throws Exception{
		File file=new File("E://a.jpg");
		write(file);
	}