jdbctemplate

Insert timestamp with JdbcTemplate in Oracle database ( ORA-01858 )

亡梦爱人 提交于 2019-12-08 01:08:04
问题 I've read a lot of stuff about this error, and still not found the mistake. I'm using JdbcTemplate to insert a row in some table with some timestamp column I'm pretty sure the timestamp is the problem, as if delete from the insert it works fine) My code: private static final String INSERT_CITAS = "INSERT INTO CITAS (" + "idCita, idServicio, " + "fechaCita, " + "idEstado, idUsuarioInicial) " + "VALUES (?, ?, ?, ?, ?)"; Object[] params = { idCita, citaQuenda.getIdServicio(), getDateToDBFormat

insert row and get generated ID

纵然是瞬间 提交于 2019-12-07 04:38:12
问题 I'm trying to use Spring's JdbcTemplate class to insert a row into a MySQL table named transaction and get the generated ID. The relevant code is: public Transaction insertTransaction(final Transaction tran) { // Will hold the ID of the row created by the insert KeyHolder keyHolder = new GeneratedKeyHolder(); getJdbcTemplate().update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection

How to use JdbcTemplate to perform Join queries

ぐ巨炮叔叔 提交于 2019-12-07 02:53:03
问题 I have the following database model create table Diary (id bigint NOT NULL AUTO_INCREMENT, creationDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP, name varchar(255) not null, description text, viewtype varchar(255) not null, member bigint, primary key (id), foreign key (member) references Member(id)); create table Page (id bigint NOT NULL AUTO_INCREMENT, creationDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP, viewtype varchar(255) not null, diary bigint, member bigint, primary key (id), foreign key

Spring NamedParameterJDBCTemplate reuse of Prepared Statements

寵の児 提交于 2019-12-07 00:36:45
问题 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

NamedJDBCTemplate Parameters is list of lists

家住魔仙堡 提交于 2019-12-06 16:34:25
I have a query which looks something like this: SELECT * FROM someTable t WHERE (t.a, t.b) IN (VALUES (1, 2), (3, 4)) And it would select any records where t.a == 1 AND t.b == 2 or t.a == 3 AND t.b == 4 . This seems to work just fine. However, I can't figure out a clean way to specify the parameter to NamedJDBCTemplate . I tried giving it a list of lists (i.e., List<List<int>> ), but it seems to blow up doing that. val query = "SELECT * FROM someTable t WHERE (t.a, t.b) IN (VALUES :values)" namedJdbcTemplate.queryForList(query, mapOf("values" to listOf(listOf(1, 2), listOf(3, 4)))) I also

(025)Spring Boot之JdbcTemplate与Transactional事务处理

微笑、不失礼 提交于 2019-12-06 15:26:40
(一)springboot提供了JdbcTemplate类来快捷的实现操作数据库,记录如下:   pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.edu.spring</groupId> <artifactId>springboot_web</artifactId> <version>1.0.0</version> <name>springboot_web</name> <!-- FIXME change it to the project's website --> <url>http://www.example.com</url> <parent> <groupId>org.springframework.boot</groupId>

spring boot atomikos multiple datasource connection pool exhausted plain jdbc

本秂侑毒 提交于 2019-12-06 14:44:33
I have a Spring Boot application that uses Atomikos for JTA Managed Transactions. It uses multiple DataSources to connect multiple Databases. The first request returns the expected Result but the second request failes with a 'Pool exhausted' Exception. I tried it with plain JDBC and JdbcTemplate with no result. It is the same. Here is my code with Spring Boot Version 1.5.8.RELEASE @SpringBootApplication @EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class, //if you are using Hibernate DataSourceTransactionManagerAutoConfiguration.class })

How to insert blob using camel SQL component with Oracle Database

你。 提交于 2019-12-06 14:00:15
问题 I am trying to insert an input stream using camel SQL component (http://camel.apache.org/sql-component.html). I have the following table in Oracle Database: table EMPLOYEE(NAME varchar(32) ,SURNAME varchar(32) , PIC BLOB ); and the following route: <route> <from uri="direct:startOracle" /> <to uri="sql:INSERT INTO EMPLOYEE (Name, surname, pics) VALUES (# , # , #)?dataSource=#oracle" /> </route> when I try to run the following code: Resource r = contex.getResource("classpath:file/ciao.jpg");

Insert timestamp with JdbcTemplate in Oracle database ( ORA-01858 )

烈酒焚心 提交于 2019-12-06 12:31:26
I've read a lot of stuff about this error, and still not found the mistake. I'm using JdbcTemplate to insert a row in some table with some timestamp column I'm pretty sure the timestamp is the problem, as if delete from the insert it works fine) My code: private static final String INSERT_CITAS = "INSERT INTO CITAS (" + "idCita, idServicio, " + "fechaCita, " + "idEstado, idUsuarioInicial) " + "VALUES (?, ?, ?, ?, ?)"; Object[] params = { idCita, citaQuenda.getIdServicio(), getDateToDBFormat(citaQuenda.getFechaCita()), ESTADO_INICIAL, USUARIO_INICIAL }; String queryCitas = INSERT_CITAS; super

解决jdbcTemplate和jpa查询TINYINT(1)返回BOOLEAN的问题

三世轮回 提交于 2019-12-06 06:30:14
问题背景 在项目中使用jpa和jdbcTemplate时,发现当对Tinyint类型的数据进行查询时,会被当作boolean类型返回。 而在项目中,我们使用了大量的Tinyint来做枚举值,被当作布尔类型返回后,造成了程序的异常。 status TINYINT(1) NOT NULL DEFAULT 0; 分析 在mysql的官网 numeric-type-overview 这篇文档里面写到 BOOL, BOOLEAN These types are synonyms for TINYINT(1). A value of zero is considered false. Nonzero values are considered true 也就是说,在mysql中对 TINYINT(1) 和 BOOLEAN 的处理是一样的。 解决 查了不少文档,都是对 jpa 或者 jdbcTemplate 的查询方法进行扩展,在返回的数据进行Mapper匹配时,判断如果是TINYINT类型,就作特殊处理。 虽然这样能解决问题,但像这样普遍的问题,我相信mysql肯定有过考虑,然后在mysql的 官方文档 里面发现了这个配置 The data type returned for TINYINT(1) columns when tinyInt1isBit=true (the default)