There is nothing. Take MYSQL as an example;
Create a table in the database,
Write a test class later
Test by myself is absolutely available
Import java. Io. bytearrayinputstream;
Import java. Io. file;
Import java. Io. fileinputstream;
Import java. SQL. connection;
Import java. SQL. drivermanager;
Import java. SQL. preparedstatement;
/**
* The test is successful in the MySQL database, and it is found that the Blob database of MySQL does not support image storage, only supports
* Local data storage of less than 65535 bytes. However, other large databases support image storage.
*/
Public class insertblob {
Public static void main (string [] ARGs ){
Try {
File F = new file ("C: \ bsmain_runtime.log ");
Long length = f. Length ();
Fileinputstream FCM = new fileinputstream ("C: \ bsmain_runtime.log ");
Byte [] imagebytes = new byte [(INT) length];
Int bytelength = FCM. Read (imagebytes, 0, (INT) length );
Bytearrayinputstream BAIS = new bytearrayinputstream (imagebytes );
Class. forname ("com. MySQL. JDBC. Driver ");
Connection con = drivermanager. getconnection ("JDBC: mysql: // localhost/test", "root", "Java ");
Preparedstatement pstmt = NULL;
/*
Create Table mypicture
(
Name varchar (20 ),
Image blob
);
*/
Pstmt = con. preparestatement ("insert into mypicture (name, image) values (?,?) ");
Pstmt. setstring (1, "001 ");
Pstmt. setbinarystream (2, BAIS, bytelength );
Pstmt.exe cuteupdate ();
System. Out. println ("file length:" + length );
System. Out. println ("Byte Length:" + bytelength );
System. Out. println ("inserted successfully .");
} Catch (exception e ){
E. printstacktrace ();
}
}
}