@Test
Public
void Run ()
throws classnotfoundexception, SQLException,FileNotFoundException {
Try {Connection conn = jdbcutils.
getconnection ();PreparedStatement PST = conn. Preparestatement ( "INSERT into MYBLOB values (null,?)");File File =
New File ( "e:\\java\\ learning \\day17-jdbc\\ Video \\1. Course introduction. avi" );FileInputStream fs =
New fileinputstream (file);Pst.setbinarystream (1, FS, (
int) file.length ());
int row = Pst.executeupdate ();
if (Row! = 0) {System.
out. println ( "Insert succeeded"); } }
Catch (Exception e) {e.printstacktrace (); } }
@Test
public void Save () throws ClassNotFoundException, SQLException,
FileNotFoundException {
try {
Connection conn = Jdbcutils.getconnection ();
PreparedStatement PST = conn
. preparestatement ("INSERT into mytext values (null,?)");
File File = new file ("E:\\java\\workspaces\\dao\\a.txt");
FileReader FR = new FileReader (file);
Pst.setcharacterstream (1, FR, (int) file.length ());
int row = Pst.executeupdate ();
if (row! = 0) {
System.out.println ("Insert Success");
}
} catch (Exception e) {
E.printstacktrace ();
}
}
Inserting a binary file and large text into the MySQL database