We are using Spring mvc for our project. In Spring.xml we want to use our newly migrated postgres db. But we are not being able to configure the url.
<bean id="jt" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="ds"></property>
</bean>
This gives us an error: [err]
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.postgresql.util.PSQLException: Invalid sslmode value: verify-full;sslrootcert=/opt/ibm/wlp/usr/servers/defaultServer/resources/iitStaticContent/root.crt
[err] at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
[err] at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:390)
You use an ampersand (&), not a semicolon (;), to separate options in an URL.
You may need to encode that as & in XML.
Related
deploying spring application to cloud foundry. Cloud foundry has postgres service, trying for jdbc connection using java-cfenv library
application.properties:
database.url = #{cfJdbcEnv.findJdbcService().getJdbcUrl()}
database.username = #{ cfJdbcEnv.findJdbcService().getUsername() }
database.password = #{ cfJdbcEnv.findJdbcService().getPassword() }
database.driverClassName = #{cfJdbcEnv.findJdbcService().getDriverClassName()}
applicationContext.xml
<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="localOverride" value="false" />
<property name="locations">
<list>
<value>classpath:application.properties</value>
<value>classpath:application-${spring.profiles.active}.properties</value>
</list>
</property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${database.driverClassName}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.username}" />
<property name="password" value="${database.password}" />
</bean>
pom.xml
<dependency>
<groupId>io.pivotal.cfenv</groupId>
<artifactId>java-cfenv-boot</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.9</version>
</dependency>
Getting error:
Caused by: java.sql.SQLException: No suitable driver found for postgres://postgres:7cpdezVdlt#apa-svc-xxxxxxxxxxxxx.apps.apa.comcast.net:5432/postgres
2021-03-03T17:35:15.01-0500 [APP/PROC/WEB/0] OUT at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:153) ~[spring-jdbc-4.0.3.RELEASE.jar:4.0.3.RELEASE]
2021-03-03T17:35:15.01-0500 [APP/PROC/WEB/0] OUT at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:144) ~[spring-jdbc-4.0.3.RELEASE.jar:4.0.3.RELEASE]
2021-03-03T17:35:15.01-0500 [APP/PROC/WEB/0] OUT at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:120) ~[spring-jdbc-4.0.3.RELEASE.jar:4.0.3.RELEASE]
2021-03-03T17:35:15.01-0500 [APP/PROC/WEB/0] OUT at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:380) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
2021-03-03T17:35:15.01-0500 [APP/PROC/WEB/0] OUT at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:228) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
2021-03-03T17:35:15.01-0500 [APP/PROC/WEB/0] OUT at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:171) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
2021-03-03T17:35:15.01-0500 [APP/PROC/WEB/0] OUT at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
2021-03-03T17:35:15.01-0500 [APP/PROC/WEB/0] OUT at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1435) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
2021-03-03T17:35:16.00-0500 [APP/PROC/WEB/0] OUT [CONTAINER] org.hibernate.engine.jdbc.spi.SqlExceptionHelper ERROR No suitable driver found for postgres://postgres:7cpdezVdlt#apa-svc-cd1365a3-c6d0-436b-811d-23fc0ec66f0c.apps.apa.comcast.net:5432/postgres
2021-03-03T17:35:16.00-0500 [APP/PROC/WEB/0] OUT [CONTAINER] org.hibernate.engine.jdbc.spi.SqlExceptionHelper WARN SQL Error: 0, SQLState: 08001
DataSource object getting instantiated with below code:
#Bean(name="dataSource")
public DataSource getDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(driverClassName);
String url =
cfEnv.findCredentialsByName("portal-db").getHost();
String username = cfEnv.findCredentialsByName("portal-db").getUsername(); String
password = cfEnv.findCredentialsByName("portal-db").getPassword();
dataSource.setDriverClassName(driverClassName);
dataSource.setUrl("jdbc:postgresql://"+url+":5432/postgres");
dataSource.setUsername(username);
dataSource.setPassword(password);
}
I am not sure why when reading database.url from application.properties file, I am getting error related to wrong url: postgres://postgres:xxxx:5432/postgres
From the error message, it seems to be getting the information. It just does not recognize the JDBC URL that's being provided by your service broker.
I would suggest the following:
Run cf env (or look at the env variables in some other way[1]) and look at VCAP_SERVICES. Look for the property that you are trying to target and confirm that the service broker has a JDBC URL set that starts with jdbc: all JDBC URLs should start with jdbc:.
As a side note, I think the format that's present use to work with the Spring Cloud Connectors, the predecessor library java-cfenv. I believe it would automatically insert the jdbc: part. Your broker may be specifying a JDBC URL that's not strictly a JDBC URL & depending on SCC to correct that.
If you are able to confirm that the URL is just missing the leading jdbc: then you can a.) contact the maker of your service broker (who makes the integration with CF) and ask them to fix this and b.) adjust the way that you're setting the database.url in application.properties to see if you can reformat it in the correct way.
Perhaps something like this (although I didn't test it):
database.url = jdbc:#{cfJdbcEnv.findJdbcService().getJdbcUrl()}
I believe there's a known issue for this, see https://github.com/pivotal-cf/java-cfenv/issues/127 and there is a code commit linked. So it looks like this should eventually start working, once a new release is cut & you upgrade to that release. You can monitor the Github issue for more details. UPDATE this should be fixed in release 2.3.0+.
[1] - Other ways you could look at the env variables: cf ssh into the container & cat /proc/<pid>/environ or dump the env variables through the spring boot actuator /env endpoint.
I setup a MessageStore in Spring Integration using JDBC, following there's my configuration:
<bean id="queryProvider" class="org.springframework.integration.jdbc.store.channel.MySqlChannelMessageStoreQueryProvider" />
<!-- JDBC message store configuration -->
<bean id="store" class="org.springframework.integration.jdbc.store.JdbcChannelMessageStore">
<property name="dataSource" ref="basicDataSource" />
<property name="channelMessageStoreQueryProvider" ref="queryProvider" />
<property name="region" value="TX_TIMEOUT" />
<property name="usingIdCache" value="true" />
</bean>
My underlying DB is Microsoft SQL Server 2012 and when starting up the server I get the following exception:
nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'LIMIT'.
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:605)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:639)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:664)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:704)
How can I fix this problem?
The best way to implement SqlServerChannelMessageStoreQueryProvider and don't use MySqlChannelMessageStoreQueryProvider, because those RDBMS vendors use different DML.
Feel free to raise a JIRA ticket and even contribute!
Environment : jBPM 6.0.1.Final, jboss EAP 6.2,spring data jpa 1.4.3.RELEASE,hibernate 4.1.1.Final,spring 4.0.0.RELEASE
I'm facing connection pooling leakage issue with jBPM6 tables and hibernate is firing 50+ queries to complete a single task. Let me explain you clearly.
In my application I'm performing DML operations on application related tables, I'm observing the connection realeasing machanism by debug as
DEBUG [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool]
(http-/127.0.0.1:8080-4) mysqlDS: returnConnection(3492713e, false)
[1/20]
Connection pooling mechanism works fine and then I submitted a task to be completed by jbpm,some data inserting into jbpm6 tables like SessionInfo, Task and when data inserted,connection is not releasing and for next task also it is not using opened connections and opening new connections and go on.. Finally I'm getting the following message due to jbpm6 tables.
Caused by: java.sql.SQLException: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/datasources/mysqlDS
at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:147)
at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:70) [hibernate-entitymanager-4.2.7.SP1-redhat-3.jar:4.2.7.SP1-redhat-3]
at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:292) [hibernate-core-4.2.7.SP1-redhat-3.jar:4.2.7.SP1-redhat-3]
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:214) [hibernate-core-4.2.7.SP1-redhat-3.jar:4.2.7.SP1-redhat-3]
... 111 more
I'm using org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean and org.springframework.orm.jpa.JpaTransactionManager for session and transaction which is working for tables i insert data. But not working for data inserting by jbpm6.
I configured <property name="hibernate.connection.release_mode" value="auto"/> as well but not useful to get the connection back.
<!--Following entity manager for Mysql database-->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="persistenceUnitName" value="masterDataMysql"/>
</bean>
<!--Transaction manager for both H2 and Mysql-->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
Click here For error log
UPDATE : This is happening due to connections are not closing by jBPM6
Please help how to solve connection leaking issue with jbpm6 ???
Any help is highly appreciated.
I have a spring XML config file called appConfig.xml which contains a datasource bean and another JDBCtemplate to which datasource is passed as an argument:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/test"/>
</bean>
<bean id="JDBCTemplate" class="com.myprojects.JDBCTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
I get an error :
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'JDBCTemplate' defined in file [appConfig.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'dataSource' threw exception; nested exception is java.lang.IllegalArgumentException: Property 'dataSource' is required
From what I see from this error, it is not able to pass dataSource to JDBCTemplate. The logs also says:
Loaded JDBC driver: com.mysql.jdbc.Driver
I have all dependencies mentioned in pom.xml and I verified that necessary jars for spring are loaded and mysql jdbc connector is also loaded. Any clues on what the issue may be?
I tried a different project where I manually added all spring dependencies and mysql jdbc connector as part of library. It worked fine there. But while trying to include dependencies via pom.xml, I'm facing this issue. So I'm assuming this is to do with some dependency not being pulled in or something. But unable to figure out which one from the error.
It thinks your class JDBCTemplate does not have a property named dataSource
Perhaps you don't have a public method setDataSource() that has a single argument of the right type.
Perhaps it is private.
Perhaps it is spelled wrong.
I'm not experienced in Java and Spring. I try to write a program that uses JdbcTemplate for Data access. I use DBCP pooling, here it is:
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:#192.168.2.7:1521:xe" />
<property name="username" value="manifesto" />
<property name="password" value="manifesto" />
<property name="initialSize" value="2" />
<property name="maxActive" value="4" />
</bean>
My application perform several update operations and then throws an exception:
7053 [SenderThread-0] DEBUG org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
Exception in thread "SenderThread-0" org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
The Connection descriptor used by the client was:
192.168.2.7:1521:xe
)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:572)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:811)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:867)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:875)
at org.springframework.jdbc.core.simple.SimpleJdbcTemplate.update(SimpleJdbcTemplate.java:249)
at com.talutek.manifesto.dao.firestorm.dao.spring.MessageItemsTableDaoImpl.update(MessageItemsTableDaoImpl.java:52)
at com.talutek.manifesto.lib.MessageItemMngr.updateItem(MessageItemMngr.java:115)
at com.talutek.manifesto.gw.SenderThread.run(SenderThread.java:42)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
The Connection descriptor used by the client was:
192.168.2.7:1521:xe
)
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
... 9 more
Caused by: java.sql.SQLException: Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
The Connection descriptor used by the client was:
192.168.2.7:1521:xe
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:110)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:171)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:496)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:411)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:490)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:202)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:465)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
... 13 more
When I change pool settings(pool size), the application can run some more times but it then crashes. I think the problem is related to pooling but I couldn't solve it.
Any suggestions?
The same error occurred for me when lots of threads accessed the database simultaneously, and I had a separate DBCP BasicDataSource and a separate Spring JdbcTemplate for each thread.
By making both the BasicDataSource and the JdbcTemplate a singleton shared by all threads, I could avoid this error. This is also what SpringSource recommends.
A google search would have helped: http://www.dba-oracle.com/sf_ora_12519_tns_no_appropriate_service_handler_found.htm
Few suggestions:
Use app server pools if possible
Use c3p0 than DBCP
Use oracle.jdbc.pool.OracleDataSource