spring-jdbc

How to call stored procedure to read return value and out parameter both in Spring?

筅森魡賤 提交于 2019-12-11 06:57:08
问题 I have a stored procedure which returns an Integer as well as an Out Parameter which is of type VARCHAR. I am using Spring 2.5.6 and unable to find a way to read the return value as well as Out Parameter at the same time. SimpleJdbcCall.executeFunction(..) have a facility to read the stored procedure return value but no facility for Out Parameter. SimpleJdbcCall.execute(..) can read Out parameters. There are other ways also in Spring to do the above. Am I missing something in Spring which can

csv output using spring-jdbctemplate during fetching multiple rows

空扰寡人 提交于 2019-12-11 06:48:36
问题 I am using spring jdbctemplate to interact with Oracle database. For fetching multiple rows for a given condition, I want to store the result in a csv file having Column names as the header. I tried few ways - List<Bean> list = jdbcTemplate.query('query','parameters',customizedrowmapper); In customizedrowmapper, I am fetching the rows from result set and setting the fields in Bean class. I could not find any easy way to convert from bean to csv file. As I dont have access to bean class code.

Using “where in” in spring-jdbc

半城伤御伤魂 提交于 2019-12-11 06:42:30
问题 Is there a way to delete a bunch of elements using "where... in" in SQL, like so: HashSet<String> idStrings = ...; SimpleJdbcTemplate template = getTemplate(); template.update("DELETE FROM records WHERE idstring IN (?)", idStrings); I am trying to get some old code to work that uses this method, but whenever I try to run it the Oracle JDBC drivers throw an exception: QL state [99999]; error code [17004]; Invalid column type; nested exception is java.sql.SQLException: Invalid column type This

jdbcTemplate.update freezes

蓝咒 提交于 2019-12-11 06:33:58
问题 I'm using a Spring JdbcTemplate without a "transactionManager" since I have mostly select to do. When I try to call select queries from JUnit, it works, but when I try to call an "update", it freezes the test (no connection timeout, nothing, just waiting). I've seen examples of jdbcTemplates insert/update without any transactionManager, but could it be the problem here ? public void insert(String param1, String param2) { String sql = "UPDATE MYTABLE SET name = :param1 where first_name =

JDBC prepared statement creates one extra database hit without any params

♀尐吖头ヾ 提交于 2019-12-11 04:58:46
问题 I have one annoying issue and i can not figure out why it is happening. To give you short introduction, i implemented batch processing (batch insert) using MySql and JDBC template on my Spring Boot project. So basically batch insert is working like it should, and performance is really amazing, BUT there is this one small issue that really is annoying and it causes constraint exception when i am inserting in one table that has unique key on two columns (id, value). So i have this code: private

Creating multiple object with one response using Spring FrameWork

会有一股神秘感。 提交于 2019-12-11 04:51:51
问题 This is my first time using Spring to add and get data from a database . I have successfully established connection with my database and can add Plants with only id and plantName but now for the part that I do not understand. How can I create an RowMapper or something else that would work with a loop that would get the Plant and go over all PlantParts to get me the object I need. I should note that Plant is just an Object I created to ask here to keep it cleaner and easier to answer. @Data

How to set fetchSize for concrete query?

你。 提交于 2019-12-11 04:25:21
问题 I want to set fetchSize only for one query and I can't find appropriate api for that. my code looks like this: jdbcTemplate.query(query, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException {...} ); How can I pass fetchSize to the query ? 回答1: This can be done using PreparedStatementSetter (JavaDoc) Given the query select * from mytable where user_id > ? You can use jdbcTemplate.query(query, new PreparedStatementSetter() { @Override public void

SpringBoot and SpringJDBC multiple datasources

旧街凉风 提交于 2019-12-11 02:23:54
问题 I am trying to use two datasources with my SpringBoot application and can't get the second datasource to autowire. I have tried many things but this is the closest I have come: My Yaml file: spring: first-datasource: url: MyURLString1 username: User password: Password driver-class-name: oracle.jdbc.OracleDriver second-datasource: url: MyURLString2 username: User password: Password driver-class-name: oracle.jdbc.OracleDriver My Application Class: @SpringBootApplication public class

HSQLDB Trigger Statement ERROR when using SimpleJdbcTestUtils.executeSqlScript()

夙愿已清 提交于 2019-12-11 00:06:25
问题 I'm currently trying to load a sql script to create a HSQL database. This is done by using the following code: Resource resource = new ClassPathResource("/create-table.sql"); SimpleJdbcTestUtils.executeSqlScript(template, resource, Boolean.FALSE); The script contains the create statement of a trigger: CREATE TRIGGER t BEFORE UPDATE ON SUBJECTS REFERENCING NEW AS newrow OLD AS oldrow FOR EACH ROW BEGIN ATOMIC SET newrow.VERSION = oldrow.VERSION + 1; END; When running the tests using this code,

How to execute multi batch delete in JdbcTemplate?

最后都变了- 提交于 2019-12-10 23:24:14
问题 I want to delete multiple database entries at once. Each entry should only be deleted if 3 fields match (here: name, email, age). If I'd just wanted to delete by a single property, I'd go for: String sql = "DELETE FROM persons WHERE (email) IN (?)"; JdbcTemplate template; template.execute(sql, Arrays.asList(emails...)); But what if my condition is formed by multiple fields? String sql = "DELETE FROM persons WHERE (name, email, age) IN (?, ?, ?)"; JdbcTemplate template; template.execute(sql, .