spring-jdbc

jdbctemplate count queryForInt and pass multiple parameters

◇◆丶佛笑我妖孽 提交于 2020-06-11 20:13:33
问题 How can I pass multiple parameters in jdbcTemplate queryForInt to get the count. I have tried this, Integer count = this.jdbcTemplate .queryForInt("select count(name) from table_name where parameter1 = ? and parameter2 = ?", new Object[]{parameter1,parameter2}); But its showing queryForInt as strikes. 回答1: Both queryForInt() and queryForLong() are deprecated since version 3.2.2 (correct me if mistake). To fix it, replace the code with queryForObject(String, Class). this.jdbcTemplate

jdbctemplate count queryForInt and pass multiple parameters

二次信任 提交于 2020-06-11 20:12:43
问题 How can I pass multiple parameters in jdbcTemplate queryForInt to get the count. I have tried this, Integer count = this.jdbcTemplate .queryForInt("select count(name) from table_name where parameter1 = ? and parameter2 = ?", new Object[]{parameter1,parameter2}); But its showing queryForInt as strikes. 回答1: Both queryForInt() and queryForLong() are deprecated since version 3.2.2 (correct me if mistake). To fix it, replace the code with queryForObject(String, Class). this.jdbcTemplate

DuplicateKeyException raised when using Spring JdbcMetadataStore (Oracle)

别来无恙 提交于 2020-05-24 02:05:31
问题 My current configuration of file:inbound-channel-adapter is working fine. I'm running the application in multiple servers and only one is actually processing the file. Database table INT_METADATA_STORE also updated successfully. Issue I'm facing is that one of the servers are still trying to insert the record and below exception is raised: org.springframework.messaging.MessagingException: nested exception is org.springframework.dao.DuplicateKeyException: PreparedStatementCallback; SQL [INSERT

How to search string LIKE 'something%' with Java Spring Framework?

心已入冬 提交于 2020-03-17 06:49:05
问题 I've got a MySQL table with Foos. Each Foo has a numeric non-unique code and a name. Now I need to find if any Foo with one of certain codes happens to have a name that starts with a given string. In normal SQL this would be trivial: select * from FOO where CODE in (2,3,5) and NAME like 'bar%'; But how would I properly do this in Spring now? Without the need for the 'like' operator I'd do it like this: public List<Foo> getByName(List<Integer> codes, String namePart) { String sql = "select *

Spring - @Transactional - What happens in background?

ぃ、小莉子 提交于 2020-03-05 04:05:12
问题 I want to know what actually happens when you annotate a method with @Transactional ? Of course, I know that Spring will wrap that method in a Transaction. But, I have the following doubts: I heard that Spring creates a proxy class ? Can someone explain this in more depth . What actually resides in that proxy class? What happens to the actual class? And how can I see Spring's created proxied class I also read in Spring docs that: Note: Since this mechanism is based on proxies, only 'external'

Bean is not formed for datasource in Spring MVC Project

最后都变了- 提交于 2020-03-04 18:48:10
问题 I am facing error "Property datasource is required". Below is the configuration in dao-beans xml. <bean id="Template" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="java:/comp/env/jdbc/TEMPLATES" /> </bean> <bean id="languageDao" class="com.test.daoImpl.LanguageDAOImpl" init-method="init"> <property name="cspLanguageGet" value="csp_LANGUAGE_Get" /> </bean> Class has the following configurations: private DataSource Template; private SimpleJdbcCall

why we use MapSqlParameterSource

感情迁移 提交于 2020-02-25 07:20:06
问题 I am new to spring world, in above code i understand query but i don't get why "new MapSqlParameterSource("username" ,username)" is used? public boolean exists(String username) { return jdbc.queryForObject("select count(*) from users where username=:username", new MapSqlParameterSource("username" ,username),Integer.class)>0; } what is the purpose of using it? Thanks in advance 回答1: It is because some developers do not like use ? in a sql sentence. This ? is named or referred how (mostly the

insert varbinary value from hex literal in Microsoft SQL Server

六眼飞鱼酱① 提交于 2020-02-24 12:23:05
问题 I have a SpringBoot app, where I use jdbcTemplate to insert a row to a mssql int numOfRowsAffected = remoteJdbcTemplate.update("insert into dbo.[ELCOR Resource Time Registr_] " + "( [Entry No_], [Record ID], [Posting Date], [Resource No_], [Job No_], [Work Type], [Quantity], [Unit of Measure], [Description], [Company Name], [Created Date-Time], [Status] ) " + " VALUES (?,CONVERT(varbinary,?),?,?,?,?,?,?,?,?,?,?);", ELCORResourceTimeRegistr.getEntryNo(), ELCORResourceTimeRegistr.getEntryNo()),

Retrieve a list of lists in one SQL statement

血红的双手。 提交于 2020-02-07 01:58:07
问题 I have two tables (say) Person and Parent with Parent-Person being many to one relationship, so a person can have many parents, direct and indirect (grandparents etc). Parent has foreign key personId and primary key of Person is of course, personId. Person table Id <PK> Parent table Id<PK> ParentPersonId <FK into Person > Person has rows with values PK 1 2 3 Parent has rows with values 1, 2 1, 3 2, 3 so person 1 has parents 2, 3 I eapect to get List<Person> [ {1, {2,3}}, {2, {3}}, {3} ] I am

HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@2a84e649 (This connection has been closed.)

我们两清 提交于 2020-01-24 21:49:27
问题 I'm using Postgresql and spring boot 2.0.4. The below error is thrown when trying to execute the queries one after the other. I've executed the following query, and the count keeps on increasing. SELECT COUNT(*) FROM pg_stat_activity WHERE state ILIKE '%idle%'; I've used these properties and dependencies for connection pool. Yet, it gives the same error spring.datasource.dbcp2.initial-size=10 spring.datasource.dbcp2.max-total=25 spring.datasource.dbcp2.pool-prepared-statements=true spring