spring-jdbc

how can I batchUpdate with a query that requires 2 parameters and only one of them is stored in a list

℡╲_俬逩灬. 提交于 2019-12-01 14:18:05
I use Spring-JDBC to insert the list of facebook friends for a user in my MySQL database. I have a final Long that contains the user uid and a List that contains the list of his friends. my query is: final String sqlInsert="insert into fb_user_friends(fb_uid,friend_uid) values(?,?)"; I create batch parameters using SqlParameterSourceUtils SqlParameterSource[] batch = SqlParameterSourceUtils.createBatch(friendsList.toArray()); and I execute the insert using: int[] insertCounts = this._jdbcTemplate.batchUpdate(sqlInsert,batch); the problem here that the list contains only the 2nd parameter that

Spring JDBC - Last inserted id

天大地大妈咪最大 提交于 2019-12-01 13:11:31
I'm using Spring JDBC. Is a simple way to get last inserted ID using Spring Framework or i need to use some JDBC tricks ? jdbcTemplate.update("insert into test (name) values(?)", params, types); // last inserted id ... I found something like below, but i get: org.postgresql.util.PSQLException: Returning autogenerated keys is not supported. KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement( Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement(

Spring JDBC - Last inserted id

你。 提交于 2019-12-01 10:57:08
问题 I'm using Spring JDBC. Is a simple way to get last inserted ID using Spring Framework or i need to use some JDBC tricks ? jdbcTemplate.update("insert into test (name) values(?)", params, types); // last inserted id ... I found something like below, but i get: org.postgresql.util.PSQLException: Returning autogenerated keys is not supported. KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement

Pass array as input parameter to an oracle stored procedure using simple jdbc call

江枫思渺然 提交于 2019-12-01 10:54:45
Here is my oracle procedure specifications CREATE OR REPLACE PACKAGE PKG_RE_FI AS PROCEDURE PRC_RE_FI_DETAILS(P_FAN_NO IN VARCHAR2, P_REF_ID IN TY_APP_REF_ID, P_COMMENTS IN VARCHAR2, P_BILLING_FLAG IN VARCHAR2, P_STATUS OUT VARCHAR2); END PKG_RE_FI; TY_APP_REF_ID is CREATE OR REPLACE TYPE ty_app_REF_ID as varray(500) of obj_array_ref_id CREATE OR REPLACE TYPE obj_array_ref_id AS OBJECT( app_ref_id VARCHAR2(100) ) I am using Spring JDBC Framework(SimpleJdbcCall object) to execute above procedure. Below is the code snippet in which i have declared this.reFIJdbcCall = new SimpleJdbcCall

Pass array as input parameter to an oracle stored procedure using simple jdbc call

只愿长相守 提交于 2019-12-01 07:34:06
问题 Here is my oracle procedure specifications CREATE OR REPLACE PACKAGE PKG_RE_FI AS PROCEDURE PRC_RE_FI_DETAILS(P_FAN_NO IN VARCHAR2, P_REF_ID IN TY_APP_REF_ID, P_COMMENTS IN VARCHAR2, P_BILLING_FLAG IN VARCHAR2, P_STATUS OUT VARCHAR2); END PKG_RE_FI; TY_APP_REF_ID is CREATE OR REPLACE TYPE ty_app_REF_ID as varray(500) of obj_array_ref_id CREATE OR REPLACE TYPE obj_array_ref_id AS OBJECT( app_ref_id VARCHAR2(100) ) I am using Spring JDBC Framework(SimpleJdbcCall object) to execute above

Large ResultSet on postgresql query

一笑奈何 提交于 2019-12-01 06:26:55
I'm running a query against a table in a postgresql database. The database is on a remote machine. The table has around 30 sub-tables using postgresql partitioning capability . The query will return a large result set, something around 1.8 million rows. In my code I use spring jdbc support, method JdbcTemplate.query , but my RowCallbackHandler is not being called. My best guess is that the postgresql jdbc driver (I use version 8.3-603.jdbc4) is accumulating the result in memory before calling my code. I thought the fetchSize configuration could control this, but I tried it and nothing changes.

Tomcat/Hibernate connection to MySql fails with “Communications link failure” & “Permission denied”

夙愿已清 提交于 2019-12-01 05:51:34
I'm trying to connect to MySql (=MariaDB) on the localhost (lets call it A) from a tomcat webapp using Hibernate, but keep getting Communication link failure (the full exception trace attached below). I have another replica of the DB on a different machine (lets call it B) and also using a 3rd computer for development (lets call it C). 1) I have no issues connecting from C to either of the DBs (A & B). 2) On "A" I have no problems connecting locally to the DB (running 'mysql -u' command). I also have no problems doing telnet on port 3306 to either A or B. so I assume both DBs are up and

Large ResultSet on postgresql query

我的未来我决定 提交于 2019-12-01 04:09:41
问题 I'm running a query against a table in a postgresql database. The database is on a remote machine. The table has around 30 sub-tables using postgresql partitioning capability. The query will return a large result set, something around 1.8 million rows. In my code I use spring jdbc support, method JdbcTemplate.query, but my RowCallbackHandler is not being called. My best guess is that the postgresql jdbc driver (I use version 8.3-603.jdbc4) is accumulating the result in memory before calling

Should I close JNDI-obtained data source?

浪子不回头ぞ 提交于 2019-12-01 03:58:39
Update: Apparently Tomcat, starting with 7.0.11, closes the DataSource for you, so it's not available in the webapp's contextDestroyed. See: https://issues.apache.org/bugzilla/show_bug.cgi?id=25060 Hi, I'm using Spring 3.0 and Java 1.6. If I get a data source this way: <bean id="dataSource" class="my.data.Source" destroy-method="close"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/> <property name="url" value="jdbc:oracle:thin:@localhost:1521:home"/> <property name="username" value="user"/> <property name="password" value="pw"/> </bean> then the data source is

Getting “Invalid column type” excecption, while using NamedParameterJDBCTemplate for insertion

笑着哭i 提交于 2019-12-01 03:31:46
问题 I am using below code while inserting a row into database(oracle 10g xe,jar: ojdbc14.jar) String sql = "INSERT INTO SPONSOR_TB(ID,NAME,INDUSTRY_TYPE,IS_REPORTING_SPONSOR,IS_NOT_SOLICITE) VALUES(SEQ_SPONSOR_ID.NEXTVAL,:NAME1,:INDUSTRY_TYPE,:IS_REPORTING_SPONSOR,:IS_NOT_SOLICITE)"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("NAME1",sponsor.getName()); paramSource.addValue("INDUSTRY_TYPE", sponsor.getIndustryType()); paramSource.addValue("IS_NOT