回答編集履歴
3
型がPreparedStatementになっていなかったので修正
answer
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
### 追記
|
7
7
|
参考記事から自分で落とし込む技術がないというギブアップ宣言をされたのでやり方を書いておきます。
|
8
8
|
```Java
|
9
|
-
|
9
|
+
PreparedStatement stmt = conn.prepareStatement("insert into ports (imgdat) values (?)";
|
10
10
|
stmt.setBinaryStream(1,new ByteArrayInputStream(sendData), sendData.length);
|
11
11
|
stmt.executeUpdate();
|
12
12
|
```
|
2
typo修正
answer
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
### 追記
|
7
7
|
参考記事から自分で落とし込む技術がないというギブアップ宣言をされたのでやり方を書いておきます。
|
8
8
|
```Java
|
9
|
-
Statement stmt = conn.
|
9
|
+
Statement stmt = conn.prepareStatement("insert into ports (imgdat) values (?)";
|
10
10
|
stmt.setBinaryStream(1,new ByteArrayInputStream(sendData), sendData.length);
|
11
11
|
stmt.executeUpdate();
|
12
12
|
```
|
1
追記
answer
CHANGED
@@ -1,4 +1,19 @@
|
|
1
1
|
JDBCでバイナリデータをBLOB型に入れたいのであれば、SQL文に直接書くのではなく[PreparedStatement#setBinaryStream](https://docs.oracle.com/javase/jp/6/api/java/sql/PreparedStatement.html#setBinaryStream(int, java.io.InputStream))を使わないと無理です。
|
2
2
|
|
3
3
|
【やり方参考記事】
|
4
|
-
[http://www63.tok2.com/home2/jd4/BLOBbasics.html](http://www63.tok2.com/home2/jd4/BLOBbasics.html)
|
4
|
+
[http://www63.tok2.com/home2/jd4/BLOBbasics.html](http://www63.tok2.com/home2/jd4/BLOBbasics.html)
|
5
|
+
|
6
|
+
### 追記
|
7
|
+
参考記事から自分で落とし込む技術がないというギブアップ宣言をされたのでやり方を書いておきます。
|
8
|
+
```Java
|
9
|
+
Statement stmt = conn.preparedStatement("insert into ports (imgdat) values (?)";
|
10
|
+
stmt.setBinaryStream(1,new ByteArrayInputStream(sendData), sendData.length);
|
11
|
+
stmt.executeUpdate();
|
12
|
+
```
|
13
|
+
|
14
|
+
あとついでに指摘ですが、以下のコードではクラス変数のsendDataに何も保存されていません。
|
15
|
+
```Java
|
16
|
+
byte[] sendData = baos.toByteArray(); // ←クラス変数への代入ではなく、新しいローカル変数へ代入している
|
17
|
+
////////////
|
18
|
+
sendData = baos.toByteArray(); // ←こうしないと意味ない
|
19
|
+
```
|