MySQLのBLOBにバイナリデータを保管するサンプル(java struts)
//SubmitFormというFormにfilenameという入力フィールドを作成
SubmitForm wf = (SubmitForm) form;
FormFile ff = (FormFile) wf.getFilename();
String filename = ff.getFileName();
int size = ff.getFileSize();
InputStream is = ff.getInputStream();
int id = 1;
//DBをOPENする処理を入れる
sql = "REPLACE INTO BLOB_DATA VALUES(?, ?, ?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, id + "");
pstmt.setString(2, filename);
pstmt.setBinaryStream(3, is, size);
pstmt.executeUpdate();
//DBをCLOSEする処理を入れる
ライブラリに以下のふたつが必要
commons-fileupload-1.1.1.jar
commons-io-1.3.jar
#今日はバレンタインデー。義理チョコ1個もらった♪
#Googleのロゴもチョコレート。
//SubmitFormというFormにfilenameという入力フィールドを作成
SubmitForm wf = (SubmitForm) form;
FormFile ff = (FormFile) wf.getFilename();
String filename = ff.getFileName();
int size = ff.getFileSize();
InputStream is = ff.getInputStream();
int id = 1;
//DBをOPENする処理を入れる
sql = "REPLACE INTO BLOB_DATA VALUES(?, ?, ?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, id + "");
pstmt.setString(2, filename);
pstmt.setBinaryStream(3, is, size);
pstmt.executeUpdate();
//DBをCLOSEする処理を入れる
ライブラリに以下のふたつが必要
commons-fileupload-1.1.1.jar
commons-io-1.3.jar
#今日はバレンタインデー。義理チョコ1個もらった♪
#Googleのロゴもチョコレート。