LoginSignup
0
0

More than 3 years have passed since last update.

JDBI3でInputStreamをBindしたい時

Posted at

JDBI2ではできたのに

@SqlUpdate("update samples set file = :file where flag = true")
int updateFile(@Bind("file") InputStream file);
@SqlUpdate("update samples set file = :file where flag = true")
fun updateFile(@Bind("file") file: InputStream?): Int

JDBI3ではできなくなっている...

org.jdbi.v3.core.statement.UnableToCreateStatementException: No argument factory registered for type ...

のようなエラーが出てくる

GitHubでエラーメッセージを検索したところ、↓が怪しい

return new UnableToCreateStatementException("No argument factory registered for '" + value + "' of qualified type " + qualifiedType, ctx);

どうやら、Bind対象のオブジェクトは Argument interfaceを実装している必要がある

(気が向いたら詳細追記)

Bind用のInterfaceが用意されていた

解決策としては、InputStreamArgumentを使えば良い

@SqlUpdate("update samples set file = :file where flag = true")
int updateFile(@Bind("file") InputStreamArgument file);
@SqlUpdate("update samples set file = :file where flag = true")
fun updateFile(@Bind("file") file: InputStreamArgument?): Int

第一引数に、InputStream
第二引数に、Streamのサイズ
第三引数に、ASCIIか否かを渡す

public InputStreamArgument(InputStream stream,
                           int length,
                           boolean ascii)
Parameters:
stream - the stream to bind
length - the length of the stream
ascii - true if the stream is ASCII
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0