spring-jdbc

Spring NamedParameterJDBCTemplate reuse of Prepared Statements

泄露秘密 提交于 2019-12-05 05:38:36
I am using the Spring NamedParameterJdbcTemplate to fetch some values from a table. For some reason, the query runs very slow in my Java app as opposed to running the same query on SQL Management Studio. I also noticed in the profiler, the prepared statements don't get reused. If I run the same query in my JAVA app multiple times, I see different prepared statements being executed. So, not sure why the statements are not getting reused. Is the performance slow because I am using a IN clause in my query? Here is my sample java code StringBuilder vQuery = new StringBuilder(); vQuery.append("

java.sql.SQLException: Invalid column name

二次信任 提交于 2019-12-05 02:56:59
I cannot figure out why I am getting "Invalid column name" here. We have tried a variant of the sql directly in Oracle, and it works fine, but when I try it using jdbcTemplate then something is wrong. List<Dataholder> alleXmler = jdbcTemplate.query("select p.applicationid, x.datadocumentid, x.datadocumentxml " + "from CFUSERENGINE51.PROCESSENGINE p " + "left join CFUSERENGINE51.DATADOCUMENTXML x " + "on p.processengineguid = x.processengineguid " + "where x.datadocumentid = 'Disbursment' " + "and p.phasecacheid = 'Disbursed' ", (rs, rowNum) -> { return Dataholder.builder() .applicationid(rs

Spring JDBC template without Spring

对着背影说爱祢 提交于 2019-12-05 01:33:38
Is there Java library like Spring JDBC Template, with same quality of code and documentation and similar data access exceptions hierarchy , but without dependancies on other Spring modules (core/beans/context modules according to http://mvnrepository.com/artifact/org.springframework/spring-jdbc/3.0.6.RELEASE )? Spring-jdbc has direct dependency to the following libraries: spring-core , spring-beans and spring-tx . The rest of the dependencies are optional, so you don't need them actually. If these dependencies are already a lot for you, then you might have a look at Apache DbUtils . A minor

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test.spring_session' doesn't exist - Spring Boot

心不动则不痛 提交于 2019-12-05 01:30:50
I am developing springboot-springsession-jdbc-demo . When I simply run the code I get the following error. It looks to me some property must need to set in application.properties in order create the schema/tables before hand. Required configuration is already in placed and still it gives error. The code is present in https://github.com/sivaprasadreddy/spring-session-samples The error for reference: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [DELETE FROM SPRING_SESSION WHERE LAST_ACCESS_TIME < ?]; nested exception is com.mysql.jdbc.exceptions

Insert UTC/GMT date in Oracle database with Java and Spring

半世苍凉 提交于 2019-12-05 01:03:26
问题 When I insert new Date() object using jdbcTemplate to Oracle database, I can see that jdbc driver or Spring jdbcTemplate insert Date using local JVM offset. SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); Date timeZoneDate = sdf.parse("09-SEP-1987"); For example when I insert Date object created in GMT this result to inserting 08-SEP-1987 in Oracle database if JVM timezone is USA. 回答1: Neither java.util.Date nor Oracle Date stores

Specify url of jdbc:embedded-database

核能气质少年 提交于 2019-12-04 18:15:25
问题 I want to specify the URL for the jdbc:embedded-database tag. Is this not possible? For example, if I have the following in my context: <jdbc:embedded-database type="HSQL" id="dataSource"> <jdbc:script execution="INIT" location="classpath:com/example/init.sql" /> </jdbc:embedded-database> It will create an in memory database located at jdbc:hsqldb:mem:dataSource What I want to do is be able to have a different bean ID and database name... For example: <jdbc:embedded-database type="HSQL" id=

Spring + Maven: The matching wildcard is strict, but no declaration can be found for element 'jdbc:embedded-database'

泄露秘密 提交于 2019-12-04 17:37:03
问题 i am currently trying to build a little webapp that uses Spring, Hibernate and Maven (running on a tomcat). It works quite fine, except that i cannot get my embedded-database to work. I hope you can help me. I am always facing this error, when i am deploying the webapp to the Tomcat: The matching wildcard is strict, but no declaration can be found for element 'jdbc:embedded-database' During my investigations i learned that this message is pointing towards missing libraries. Therefore i added

how to query for a list<String> in jdbctemplate

隐身守侯 提交于 2019-12-04 16:24:48
问题 I'm using springs jdbctemplate and running a query like below: SELECT COLNAME FROM TABLEA GROUP BY COLNAME There are no named parameters being passed, however, column name, COLNAME , will be passed by the user. Questions Is there a way to have placeholders, like ? for column names? For example SELECT ? FROM TABLEA GROUP BY ? If I want to simply run the above query and get a List<String> what is the best way? Currently I'm doing: List <Map<String, Object>> data = getJdbcTemplate().queryForList

How to preinitialize DBCP connection pool on startup?

自闭症网瘾萝莉.ら 提交于 2019-12-04 08:27:54
The setup of my project is - Spring JDBC for persistence Apache DBCP 1.4 for connection pooling Mysql 5 on Linux Here is the log of my application that captures the interactions with the database. 2013-01-29 15:52:21,549 DEBUG http-bio-8080-exec-3 org.springframework.jdbc.core.JdbcTemplate - Executing SQL query [SELECT id from emp] 2013-01-29 15:52:21,558 DEBUG http-bio-8080-exec-3 org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource 2013-01-29 15:52:31,878 INFO http-bio-8080-exec-3 jdbc.connection - 1. Connection opened org.apache.commons.dbcp

Spring ResultSetExtractor

孤者浪人 提交于 2019-12-04 06:50:57
How to use ResultSetExtractor to retrieve data from database? here I am using oracle 10g as back end. In case of searching an Employee details from Employee Table which one is better to use ResultSetExtractor or RowMapper ? One can also use closures (lambdas) as row mapping routine since java 8: String sql = "select first_name, last_name from PERSON where id = ?"; public Person jdbcTemplate.query(sql,(rs)->{return new Person(rs.getString("first_name"), rs.getString("last_name"));}, int id); First method param is your query, second - your mapper - Person(String, String) constructor is needed.