jdbi

Dropwizard and Guice: injecting Environment

大城市里の小女人 提交于 2019-12-03 13:20:59
I am currently building a Dropwizard + Guice + Jersey-based application where the database access is being handled by JDBI for the time being. What I am trying to achieve is to have your typical enterprise architecture, where Resources access Service classes accessing a DAO class that in turn accesses the database. It would be nice to get all this wired up in a proper DI way, although I guess I can build my object graph in the run() method of the application if all else fails. So, I'm running into this problem that has been mentioned here before : Getting a DBIFactory requires both the

JDBI How can I dynamically create a WHERE clause while preventing SQL Injection?

风流意气都作罢 提交于 2019-11-30 21:14:57
I want to dynamically filter a JDBI query. The a list of parameters is passed from the UI via REST e.g. http://localhost/things?foo=bar&baz=taz http://localhost/things?foo=buz Which is (clumsily) built (Jersey @Context UriInfo::getQueryParameters -> StringBuilder) to something like this: WHERE foo=bar AND baz=taz And passed to JDBI which looks like this: @UseStringTemplate3StatementLocator public interface ThingDAO { @SqlQuery("SELECT * FROM things <where>) List<Thing> findThingsWhere(@Define("where") String where); } As far as I understand the current implementation is vulnerable to SQL

Does JDBI accept UUID parameters?

喜夏-厌秋 提交于 2019-11-30 14:59:04
问题 When using SQL Object argument binding, does JDBI work out-of-the-box with UUID parameters? I have a method such as this: @SqlQuery("EXECUTE [MyProcedure] :myField") MyDto myMethod(@Bind("myField") UUID myField); which is bound to a SQL Server stored procedure that receives a parameter like this: @myField uniqueidentifier When executed, this exception is thrown: ! com.microsoft.sqlserver.jdbc.SQLServerException: The conversion from UNKNOWN to UNKNOWN is unsupported. ! at com.microsoft

Does JDBI accept UUID parameters?

我只是一个虾纸丫 提交于 2019-11-30 13:05:56
When using SQL Object argument binding, does JDBI work out-of-the-box with UUID parameters? I have a method such as this: @SqlQuery("EXECUTE [MyProcedure] :myField") MyDto myMethod(@Bind("myField") UUID myField); which is bound to a SQL Server stored procedure that receives a parameter like this: @myField uniqueidentifier When executed, this exception is thrown: ! com.microsoft.sqlserver.jdbc.SQLServerException: The conversion from UNKNOWN to UNKNOWN is unsupported. ! at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190) ! at com.microsoft

How to use IN operator with JDBI?

巧了我就是萌 提交于 2019-11-30 02:50:53
问题 I'm trying to do a IN query using MYSQL JDBI on Dropwizard (not relevant, I assume). @SqlQuery("SELECT id FROM table where field in (<list>)") List<Integer> findSomething(@BindIn("list") List<String> someList); As suggested here, I've also annotated the class with @UseStringTemplate3StatementLocator But when I'm starting the application, I get the following error: Exception in thread "main" java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class org.skife

Jdbi - how to bind a list parameter in Java?

时光怂恿深爱的人放手 提交于 2019-11-28 12:03:35
We have an SQL statement which is executed by Jdbi ( org.skife.jdbi.v2 ). For binding parameters we use Jdbi's bind method: Handle handle = ... Query<Map<String, Object>> sqlQuery = handle.createQuery(query); sqlQuery.bind(...) However we have a problem with in-lists and currently we are using String.format for this. So our query can look like this: SELECT DISTINCT tableOne.columnOne, tableTwo.columnTwo, tableTwo.columnThree FROM tableOne JOIN tableTwo ON tableOne.columnOne = tableTwo.columnOne WHERE tableTwo.columnTwo = :parameterOne AND tableTwo.columnThree IN (%s) %s is replaced by String

How to do in-query in jDBI?

别等时光非礼了梦想. 提交于 2019-11-27 21:04:22
How can I execute somethings like this in jDBI ? @SqlQuery("select id from foo where name in <list of names here>") List<Integer> getIds(@Bind("nameList") List<String> nameList); Table: foo(id int,name varchar) Similar to @SelectProvider from myBatis. Similar questions has been asked How do I create a Dynamic Sql Query at runtime using JDBI's Sql Object API? , but somehow answer is not clear to me. Deinlandel This should work: @SqlQuery("select id from foo where name in (<nameList>)") List<Integer> getIds(@BindIn("nameList") List<String> nameList); Don't forget to annotate class containing

Dynamic Order in JDBI SQL Object Queries

半世苍凉 提交于 2019-11-27 14:06:33
How do you do ordering with SQL Object Queries in JDBI? I want to do something like: @SqlQuery( "SELECT * FROM users " + "WHERE something = :something " + "ORDER BY :orderBy :orderDir" ) List<User> getUsers( @Bind("something") Integer something , @BindOrderBy("orderBy") String orderBy , @BindOrderDir("orderDir") String orderDir ); or @SqlQuery( "SELECT * FROM users " + "WHERE something = :something " + "ORDER BY :orderBy :orderDir" ) List<User> getUsers( @Bind("something") Integer something , @Bind("orderBy") OrderBy orderBy , @Bind("orderDir") OrderDir orderDir ); I've recently been exploring

How to do in-query in jDBI?

南楼画角 提交于 2019-11-26 20:32:09
问题 How can I execute somethings like this in jDBI ? @SqlQuery("select id from foo where name in <list of names here>") List<Integer> getIds(@Bind("nameList") List<String> nameList); Table: foo(id int,name varchar) Similar to @SelectProvider from myBatis. Similar questions has been asked How do I create a Dynamic Sql Query at runtime using JDBI's Sql Object API?, but somehow answer is not clear to me. 回答1: This should work: @SqlQuery("select id from foo where name in (<nameList>)") List<Integer>

Dynamic Order in JDBI SQL Object Queries

寵の児 提交于 2019-11-26 16:36:01
问题 How do you do ordering with SQL Object Queries in JDBI? I want to do something like: @SqlQuery( "SELECT * FROM users " + "WHERE something = :something " + "ORDER BY :orderBy :orderDir" ) List<User> getUsers( @Bind("something") Integer something , @BindOrderBy("orderBy") String orderBy , @BindOrderDir("orderDir") String orderDir ); or @SqlQuery( "SELECT * FROM users " + "WHERE something = :something " + "ORDER BY :orderBy :orderDir" ) List<User> getUsers( @Bind("something") Integer something ,