jdbi

Postgresql array comparision with List input Dropwizard JDBI

試著忘記壹切 提交于 2019-12-11 15:47:19
问题 My question is similar to this PostgreSQL check if array contains any element from left-hand array but I want to execute (same query which is given in the above question) i.e. "&& operator" query via code. Dropwizard + JDBI framework. @SqlQuery("SELECT ARRAY[1,2,3,4] && <input_array>") public abstract Object query(@BindIn("input_array") List<Integer> list); @BindIn annotation does not work. Getting below error. ! org.postgresql.util.PSQLException: ERROR: operator does not exist: integer[] &&

PostgreSQL function does not exist

允我心安 提交于 2019-12-11 10:24:07
问题 I'm using the SQL query which uses a custom written function similar to this CREATE OR REPLACE FUNCTION per_cont(myarray integer[], percentile real) This works perfectly in the pgAdmin tool, but when I use this query in my java application it gives me an error: function per_cont(integer[], real) does not exist I'm using JDBI library to interact with the database. Why doesn't it find the function when running it from a java application? How can I fix it? 回答1: The error message doesn't make

JDBI like layer for cassandra

被刻印的时光 ゝ 提交于 2019-12-11 09:33:56
问题 I am developing a module having cassandra as backend. Searching for JDBI sort of library for cassandra. Cassandra java driver is my primary option. Would like to know if there is exists library for higher level abstraction on top of cassandra java driver. 回答1: The latest Java Driver comes with an object mapping API. Basically, you can annotate your Java class: @Table(keyspace = "complex", name = "accounts") public class Account { @PartitionKey private String email; private String name;

How to convert 2d array from PostgreSQL DB to java 2d array using JDBI?

落爺英雄遲暮 提交于 2019-12-11 04:04:36
问题 How can I convert a 2d char array from my Postgres DB to a native Java char[][]? This is my attempt based on this answer: import java.sql.Array; import java.sql.ResultSet; import java.sql.SQLException; import org.skife.jdbi.v2.StatementContext; import org.skife.jdbi.v2.tweak.ResultSetMapper; public class GameMapper implements ResultSetMapper<Game>{ public Game map(int index, ResultSet resultSet, StatementContext statementContext) throws SQLException { Array board = resultSet.getArray("BOARD")

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

ⅰ亾dé卋堺 提交于 2019-12-09 00:45:51
问题 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

Use JDBI to get Postgres Array Data

自闭症网瘾萝莉.ら 提交于 2019-12-08 02:39:33
问题 I have a java program using JDBI (a JDBC wrapper) to access a PostgreSQL database. One of the columns is of the array data type (mycolumn integer[]) . What the heck to I use in my mapper class? I thought resultSet.getArray("mycolumn") would be the right thing to do, but I'm not sure how to get the data out of the java.sql.Array object that gets returned. Any hints or good links on how to do this? 回答1: Array array = resultSet.getArray("mycolumn"); return nonNull(array) ? (Integer[])array

performing create-or-update with jdbi

喜夏-厌秋 提交于 2019-12-08 00:03:11
问题 For a small new project, I decided to give JDBI a try (normally I work with hibernate/jpa). I like the lightweight, annotation based dao creation using @SqlUpdate/@SqlQuery. But: There are situations where I can't be sure if I want to create an entity or update an existing one. I would place a "select" statement and depending on its return value use the insert or update statement. Question: is this somehow supported by the "interface-only" dao in jdbi? Or do I have to write a "createOrUpdate"

Using Dropwizard & JDBI to query database with multiple schemas?

人盡茶涼 提交于 2019-12-06 14:48:40
问题 I'm building a Java Rest API with DropWizard (which uses JDBI) and my requirements are that I need to query multiple MySQL schemas with the same application. It'll basically be one AWS MySQL instance housing multiple schemas -- one schema per client. What I need is a mechanism which knows which "schema" to query depending on the request -- IE: which client a request belongs to. I know how to create a DataSource, DAO, etc (using this tutorial: https://dropwizard.github.io/dropwizard/manual

Use JDBI to get Postgres Array Data

孤人 提交于 2019-12-06 06:18:58
I have a java program using JDBI (a JDBC wrapper) to access a PostgreSQL database. One of the columns is of the array data type (mycolumn integer[]) . What the heck to I use in my mapper class? I thought resultSet.getArray("mycolumn") would be the right thing to do, but I'm not sure how to get the data out of the java.sql.Array object that gets returned. Any hints or good links on how to do this? Array array = resultSet.getArray("mycolumn"); return nonNull(array) ? (Integer[])array.getArray() : null ; 来源: https://stackoverflow.com/questions/16093398/use-jdbi-to-get-postgres-array-data

performing create-or-update with jdbi

别等时光非礼了梦想. 提交于 2019-12-06 06:07:51
For a small new project, I decided to give JDBI a try (normally I work with hibernate/jpa). I like the lightweight, annotation based dao creation using @SqlUpdate/@SqlQuery. But: There are situations where I can't be sure if I want to create an entity or update an existing one. I would place a "select" statement and depending on its return value use the insert or update statement. Question: is this somehow supported by the "interface-only" dao in jdbi? Or do I have to write a "createOrUpdate" method myself (making the auto generated dao more or less obsolete)? Thanks for any hints. Thanks to