When you want to bind InputStream in JDBI3

I could do it with 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

It's not possible with JDBI3 ...

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

I get an error like

When I searched for error messages on GitHub, ↓ is suspicious

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

https://github.com/jdbi/jdbi/blob/3c93a316d5cbf9507e668b62414daae759641e93/core/src/main/java/org/jdbi/v3/core/statement/ArgumentBinder.java#L174

Apparently, the object to be bound must implement the Argument interface

(Add details if you feel like it)

Interface for Bind was prepared

The solution is to use 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

http://jdbi.org/apidocs/org/jdbi/v3/core/argument/InputStreamArgument.html

InputStream as the first argument The second argument is the size of the Stream Pass ASCII or not as the third argument

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

Recommended Posts

When you want to bind InputStream in JDBI3
When you want to dynamically replace Annotation in Java8
ProxyFactory is convenient when you want to test AOP in Spring!
A note when you want Tuple in Java
When you want to use the method outside
[Swift] Use nonzeroBitCount when you want popcnt in Swift
[Ruby] When you want to replace multiple characters
When you want to notify an error somewhere when using graphql-spring-boot in Spring Boot
If you want to recreate the instance in cloud9
Code to use when you want to process Json with only standard library in Java
When you want to explicitly write OR or AND with ransack
When you want to change the MySQL password of docker-compose
docker-compose.yml when you want to keep mysql running with docker
lombok.config when you want to pass @Qualifier to @RequiredArgsConstructor with lombok
Delegate is convenient to use when you want to reuse parts
[Ruby + Rails] When you want to register in Mailchimp's mail list together with user registration
How to write in Model class when you want to save binary data in DB with PlayFramework
Use JLine when you want to handle keystrokes on the console character by character in Java
When you want to implement Java library testing in Spock with multi-module in Gradle in Android Studio 3
When you want to reflect the Master Branch information in the Current Branch you are currently working on
I want to convert InputStream to String
If you want to include the parent class in Lombok's @builder
When you want to ZIP download the image data saved locally
Setting that converts to binding.pry when you type pry in VScode
[Docker] Magic command when you want to wipe out none image
When you have introduced devise but want to add more columns
Practice to use when you want to execute different processing groups serially
[Swift] When you want to know if the number of characters in a String matches a certain number ...
How to write when you want to keep line breaks and output while avoiding XSS in Rails
Object-oriented design that can be used when you want to return a response in form format
How to write when you want to handle "array of C language strings" like argv [] in Ruby-FFI
What to do when you want to know the source position where the method is defined in binding.pry
A memo when you want to clear the time part of the calendar
When you want Rails to disable a session for a specific controller only
Summary of means when you want to communicate with HTTP on Android
[RSpec] When you want to use the instance variable of the controller in the test [assigns is not recommended]
(Limited to Java 7 or later) I want you to compare objects in Objects.equals
Basic Rails commands you want to learn
If you want to dynamically embed values & add text to attribute values in Thymeleaf 3
The first thing to do when you want to be happy with Heroku on GitHub with Eclipse in Java
I want to get the IP address when connecting to Wi-Fi in Java
I want to display an error message when registering in the database
I want to use @Autowired in Servlet
What to do when you want to delete a migration file that is "NO FILE"
What to do when you think you can't do Groovy-> Java in IntelliJ IDEA CE
If you want to satisfy the test coverage of private methods in JUnit
You may not want to use the remove method in ArrayList very often
Android Studio memo that you want to display Toast characters in large size
If you want to modify database columns etc.
I want to send an email in Java.
I want to use arrow notation in Ruby
When the server fails to start in Eclipse
When you get lost in the class name
I want to pass APP_HOME to logback in Gradle
rsync4j --I want to touch rsync in Java.
[Xcode] I want to manage images in folders
How to bind to property file in Spring Boot
I want to be eventually even in kotlin
Things to keep in mind when committing to CRuby
What do you use when converting to String?
What to do when IllegalStateException occurs in PlayFramework