回答編集履歴
3
型がPreparedStatementになっていなかったので修正
test
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
```Java
|
16
16
|
|
17
|
-
Statement stmt = conn.prepareStatement("insert into ports (imgdat) values (?)";
|
17
|
+
PreparedStatement stmt = conn.prepareStatement("insert into ports (imgdat) values (?)";
|
18
18
|
|
19
19
|
stmt.setBinaryStream(1,new ByteArrayInputStream(sendData), sendData.length);
|
20
20
|
|
2
typo修正
test
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
```Java
|
16
16
|
|
17
|
-
Statement stmt = conn.prepare
|
17
|
+
Statement stmt = conn.prepareStatement("insert into ports (imgdat) values (?)";
|
18
18
|
|
19
19
|
stmt.setBinaryStream(1,new ByteArrayInputStream(sendData), sendData.length);
|
20
20
|
|
1
追記
test
CHANGED
@@ -5,3 +5,33 @@
|
|
5
5
|
【やり方参考記事】
|
6
6
|
|
7
7
|
[http://www63.tok2.com/home2/jd4/BLOBbasics.html](http://www63.tok2.com/home2/jd4/BLOBbasics.html)
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
### 追記
|
12
|
+
|
13
|
+
参考記事から自分で落とし込む技術がないというギブアップ宣言をされたのでやり方を書いておきます。
|
14
|
+
|
15
|
+
```Java
|
16
|
+
|
17
|
+
Statement stmt = conn.preparedStatement("insert into ports (imgdat) values (?)";
|
18
|
+
|
19
|
+
stmt.setBinaryStream(1,new ByteArrayInputStream(sendData), sendData.length);
|
20
|
+
|
21
|
+
stmt.executeUpdate();
|
22
|
+
|
23
|
+
```
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
あとついでに指摘ですが、以下のコードではクラス変数のsendDataに何も保存されていません。
|
28
|
+
|
29
|
+
```Java
|
30
|
+
|
31
|
+
byte[] sendData = baos.toByteArray(); // ←クラス変数への代入ではなく、新しいローカル変数へ代入している
|
32
|
+
|
33
|
+
////////////
|
34
|
+
|
35
|
+
sendData = baos.toByteArray(); // ←こうしないと意味ない
|
36
|
+
|
37
|
+
```
|