BLOB (Binary large object), binary large, is a container that can store binary files.
can be used to store information such as pictures
Demo1: Storing pictures
1String sql= "INSERT into Testblob (NAME,HEADIMAGFE) VALUES (?,?)";
conn=jdbcutil.getconnection ();2pstmt=conn.preparestatement (SQL);3Pstmt.setstring (1, "MM");4 5 //MySQL implements all the methods, but some methods do not pass, there is no real implementation6 //Pstmt.setblob (Parameterindex, InputStream, length)7 8InputStream is=NewFileInputStream ("d:\\a.jpg");//input Stream9 TenPstmt.setbinarystream (2, is, is.available ());//add to SQL statement One APstmt.executeupdate ();//Execution
Demo2: Get Pictures
1String sql= "SELECT * from Testblob where id=1";2Blob blob= Rs.getblob ("HEADIMAGFE");3InputStream Is=blob.getbinarystream ();//input Stream4String path= "D:\\b.jpg";5OutputStream out=NewFileOutputStream (path);//output Stream6 intLen=-1;7 byte[] buffer=New byte[1024];8 while((len= (is.read (buffer))) >0) {//Loop Output9Out.write (buffer,0, Len); Ten } One out.close (); AIs.close ();
Processing of BLOB binary objects in MySQL