spring-jdbc

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

人盡茶涼 提交于 2019-12-01 03:13:38
问题 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

Spring JDBC + Postgres SQL + Java 8 - conversion from/to LocalDate

被刻印的时光 ゝ 提交于 2019-12-01 00:58:17
问题 I am using Postgres SQL 9.2, Spring JDBC with version 4.0.5, and Java 8. Java 8 introduced new date/time API and I would like to use it, but I encountered some difficulties. I have created table TABLE_A: CREATE TABLE "TABLE_A" ( new_date date, old_date date ) I am using Spring JDBC to communicate with database. I have created Java class, which corresponds to this table: public class TableA { private LocalDate newDate; private Date oldDate; //getters and setters } this is my code which is

How to use Spring's JdbcTemplate to connect to a simple MySql database?

别等时光非礼了梦想. 提交于 2019-11-30 18:31:28
I am trying to use Spring's JdbcTemplate Class to connect to a simple MySql database based on this tutorial. In fact, I used their project setup: pom.xml <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>test</groupId> <artifactId>jdbc-test</artifactId> <version>0.0.1-SNAPSHOT</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version

How to use a list of string in NamedParameterJDBCTemplate to get results

我们两清 提交于 2019-11-30 17:23:32
Experimenting with Spring-JDBC. I am using this as reference. I am trying to get a list of actors who have the same last name. Running this code gave me the desired results: public List<String> getActorsWithSameLastName(String lastName, NamedParameterJdbcTemplate template) { String query = "SELECT FIRSTNAME FROM ACTORS WHERE LASTNAME=:LASTNAME"; Map<String, String> paramMap = new HashMap<String, String>(); paramMap.put("LASTNAME", lastName); return template.queryForList(query, paramMap, String.class); } I have a List<String> of last names. How can I get a List of actors with the list that I

Embedded HSQLDB persist data to a file

旧城冷巷雨未停 提交于 2019-11-30 15:09:52
问题 I am creating a spring based web application that uses embedded hsqldb. My spring config is pretty simple: <jdbc:embedded-database id="dataSource" type="HSQL" > <jdbc:script location="classpath:scripts/create-table-if-not-exists" /> </jdbc:embedded-database> But with this config all data is stored in memory. Here is the data source url that is created jdbc:hsqldb:mem:dataSource I need to persist data to a file. So that I can use it again after server restart. 回答1: This solution worked for me

Configure spring to connect to mysql over ssl

删除回忆录丶 提交于 2019-11-30 14:25:18
问题 I am connecting to MySQL over SSL from my Java application. I have configured MYSQL to support SSL and generated client certificates. I have imported server CA certificate and client certificate into keystore. This is how my code currently looks like String url = "jdbc:mysql://127.0.0.1:3306/MySampleDb? verifyServerCertificate =true&useSSL=true&requireSSL=true" System.setProperty("javax.net.ssl.keyStore","/home/cert/keystore"); System.setProperty("javax.net.ssl.keyStorePassword","password");

Embedded HSQLDB persist data to a file

故事扮演 提交于 2019-11-30 13:29:20
I am creating a spring based web application that uses embedded hsqldb. My spring config is pretty simple: <jdbc:embedded-database id="dataSource" type="HSQL" > <jdbc:script location="classpath:scripts/create-table-if-not-exists" /> </jdbc:embedded-database> But with this config all data is stored in memory. Here is the data source url that is created jdbc:hsqldb:mem:dataSource I need to persist data to a file. So that I can use it again after server restart. This solution worked for me <bean class="org.apache.commons.dbcp2.BasicDataSource" id="dataSource"> <property name="driverClassName"

simple jdbc wrapper

不想你离开。 提交于 2019-11-30 11:46:28
To implement data access code in our application we need some framework to wrap around jdbc (ORM is not our choice, because of scalability). The coolest framework I used to work with is Spring-Jdbc . However, the policy of my company is to avoid external dependencies, especially spring, J2EE, etc. So we are thinking about writing own handy-made jdbc framework, with functionality similar Spring-jdbc: row mapping, error handling, supporting features of java5, but without transaction support. Does anyone have experience of writing such jdbc wrapper framework? If anyone has experience of using

Spring is losing connection to the DB and does not recover or reconnect

雨燕双飞 提交于 2019-11-30 11:03:58
问题 I have a spring-boot application on the same host as the Maria DB and both are running fine for some time. But between 12 hours and 2 days it seems that the spring boot application looses the connection to the database (stacktrace) and does not recover from that. When I restart the spring application all is fine again for some time. The application is not under load and when it looses the connection the application is still working but the db connection does not recover. The DB did not

Configure spring to connect to mysql over ssl

拥有回忆 提交于 2019-11-30 10:11:27
I am connecting to MySQL over SSL from my Java application. I have configured MYSQL to support SSL and generated client certificates. I have imported server CA certificate and client certificate into keystore. This is how my code currently looks like String url = "jdbc:mysql://127.0.0.1:3306/MySampleDb? verifyServerCertificate =true&useSSL=true&requireSSL=true" System.setProperty("javax.net.ssl.keyStore","/home/cert/keystore"); System.setProperty("javax.net.ssl.keyStorePassword","password"); System.setProperty("javax.net.ssl.trustStore","/home/cert/truststore"); System.setProperty("javax.net