Use Java to store images in sqlserver
Connection conn = NULL;
Try {
Drivermanager. registerdriver (new COM. Microsoft. JDBC. sqlserver. sqlserverdriver ());
Conn = drivermanager. getconnection ("JDBC: Microsoft: sqlserver: // ip: 1433; databasename = MOFTEC", "sa", "mymm ");
}
Catch (exception E)
{
// Catch an exception and throw an ioexception
Out. println ("can not connec to the database! The exception is "+ E. tostring ());
}
Fileinputstream FCM = NULL;
File file = new file ("E:/Java/chart.jpg ");
Try {
FS = new fileinputstream (File );
} Catch (filenotfoundexception e ){
Out. println ("not find file! ");
}
Preparedstatement PS = conn. preparestatement ("insert into gs_img (Lei, years, IMG) values (?,?,?) ");
PS. setstring (1, "Ivan ");
PS. setint (2, 4 );
PS. setbinarystream (3, FS, (INT) file. Length ());
Ps.exe cuteupdate ();
PS. Close ();
Try {
FCM. Close ();
Out. println ("written in! ");
} Catch (ioexception e ){
Out. println ("FCM cann' t cloase! ");
}