I have fetched my mail from gmail account to local zimbra machine and which is stored in mysql database, which run mysql on 7306 port and /opt/zimbra/db/mysql.sock.
Now, I would like to access all those record via java program.
I have used Spring with Java program using zimbra java version 1.7.0_07-b10
Here is configuration in xml file ..
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://172.18.100.117:7306/mboxgroup8?socket=/opt/zimbra/db/mysql.sock"/>
<property name="username" value="zimbra"/>
<property name="password" value="Zy"/>
<property name="maxActive" value="10"/>
<property name="maxIdle" value="5"/>
<property name="maxWait" value="60000"/>
<property name="removeAbandoned" value="true"/>
<property name="removeAbandonedTimeout" value="60"/>
<property name="logAbandoned" value="true"/>
<property name="validationQuery" value="Select 1"/>
<property name="testOnBorrow" value="true"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="10000"/>
<property name="minEvictableIdleTimeMillis" value="60000"/>
</bean>
When I tried to connect via program, it gives me below error...
getMails- 59- Exception in getMails at Manager:org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82)
at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:182)
at org.springframework.orm.ibatis.SqlMapClientTemplate.executeWithListResult(SqlMapClientTemplate.java:219)
at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:266)
at com.cashEmail.core.dao.MailItemDAOImpl.selectByExampleWithBLOBs(MailItemDAOImpl.java:86)
at com.cashEmail.manager.CashManager.getMails(CashManager.java:48)
at com.cashEmail.core.service.CashService.getCashEmail(CashService.java:77)
at com.cashEmail.resource.CashResource.getEmails(CashResource.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Related
I am stuggelin to create a ftp connection with the spring ftpSessionFactory.
In my project I am using the xml configuration for a ftp connection with TLS (it works):
<bean id="ftpSessionFactory"
class="org.springframework.integration.ftp.session.DefaultFtpsSessionFactory">
<property name="host" value="#{configurationService.configuration.getProperty('file.transfer.server.host')}" />
<property name="port" value="#{configurationService.configuration.getProperty('file.transfer.server.port')}" />
<property name="username" value="#{configurationService.configuration.getProperty('file.transfer.server.user')}" />
<property name="password" value="#{configurationService.configuration.getProperty('file.transfer.server.password')}" />
<property name="clientMode" value="2"/>
<property name="fileType" value="2"/>
<property name="useClientMode" value="true"/>
<property name="keyManager" ref="keyManager"/>
<property name="protocol" value="TLS"/>
<property name="trustManager" ref="trustManager"/>
<property name="prot" value="P"/>
<property name="needClientAuth" value="true"/>
<property name="sessionCreation" value="true"/>
<property name="implicit" value="false"/>
</bean>
Now I need a second connection, but without TLS (dont ask :D). For that I just replaced the fields in Java:
ftpSessionFactory.setHost(host);
ftpSessionFactory.setPort(port);
ftpSessionFactory.setUsername(username);
ftpSessionFactory.setPassword(password);
ftpSessionFactory.setProtocol(StringUtils.isNoneEmpty(protocol) ? protocol : null); // <-- null for no TLS
But that gives me this error: javax.net.ssl.SSLException: 500 AUTH: unknown command.
Then I tried it the hard coded way (it works):
FTPClient f = new FTPClient();
f.connect(host);
f.login(username, password);
Now my question:
How can I modify the xml part (I guess with setter) so it works for both?
Use DefaultFtpSessionFactory instead of DefaultFtpsSessionFactory.
I'm using a spring datasource and is unable to connect to Oracle AQ Queue.
Connection connection = null;
AQSession aqSess = null;
connection = ds.getConnection();
connection.setAutoCommit(false);
DataSourceUtils.getTargetConnection(connection);
Class.forName("oracle.AQ.AQOracleDriver");
aqSess = AQDriverManager.createAQSession(connection);
aqSession = aqSess;
But still get this: oracle.jms.AQjmsException: JMS-112: Connection is invalid any tips would be appreciated.
<bean id="myId" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:#myIpAddress:dev"/>
<property name="username" value="user"/>
<property name="password" value="pass"/>
<property name="removeAbandoned" value="true"/>
<property name="initialSize" value="2"/>
<property name="maxIdle" value="8"/>
<property name="maxActive" value="30"/>
<property name="maxWait" value="60000"/>
</bean>
AQException: oracle.AQ.AQException: JMS-112: Connection is invalid
at oracle.AQ.AQDriverManager.createAQSession(AQDriverManager.java:193)
I fixed my problem using the following code:
OracleConnection oracleConnection = connection.unwrap(OracleConnection.class);
Recording it here as an answer in case others find this question when having a similar problem.
Oracle AQ doesn't match with BasicDataSource
useOracleDataSource instead
but if you want to use BasicDataSource:
In many application server environments the JDBC connection is wrapped
in an implementation specific class that delegates to the underlying
native JDBC connection. Oracle's AQ connection factory needs the
native Oracle connection and will throw an "oracle.jms.AQjmsException:
JMS-112: Connection is invalid" exception if the connection is wrapped
by a foreign class. To solve this problem you can specify a
NativeJdbcExtractor that can be used to unwrap the connection. Spring
provides a number of implementations to match the application server
environment. Here is an example for specifying a NativeJdbcExtractor.
<orcl:aq-jms-connection-factory id="connectionFactory"
use-local-data-source-transaction="true"
native-jdbc-extractor="dbcpNativeJdbcExtractor" 1
data-source="dataSource" />
<bean id="dbcpNativeJdbcExtractor"
class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"/>
<bean id="dbcpDataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
https://docs.spring.io/spring-data/jdbc/old-docs/2.0.0.BUILD-SNAPSHOT/reference/html/orcl.streamsaq.html
I have my Spring MVC app.
dispatcher-servlet.xml
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://localhost:5432/dailyjob"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
When my app is trying to connect to the database, I get the exception
Caused by: org.postgresql.util.PSQLException: ?????: ????????????
"root" ?? ?????? ???????? ??????????? (?? ??????) at
org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:398)
at
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:173)
at
org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:64)
at
org.postgresql.jdbc2.AbstractJdbc2Connection.(AbstractJdbc2Connection.java:136)
at
org.postgresql.jdbc3.AbstractJdbc3Connection.(AbstractJdbc3Connection.java:29)
at
org.postgresql.jdbc3g.AbstractJdbc3gConnection.(AbstractJdbc3gConnection.java:21)
at
org.postgresql.jdbc4.AbstractJdbc4Connection.(AbstractJdbc4Connection.java:31)
at
org.postgresql.jdbc4.Jdbc4Connection.(Jdbc4Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:393) at
org.postgresql.Driver.connect(Driver.java:267) at
java.sql.DriverManager.getConnection(DriverManager.java:664) at
java.sql.DriverManager.getConnection(DriverManager.java:208) at
org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:173)
at
org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:164)
at
org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:153)
at
org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:119)
at
org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
at
org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
... 46 more
If I'm trying to connect to mysql with
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="com.mysql.jdbc.Driver"
p:url="jdbc:mysql://localhost/dailyjob"
p:username="root"
p:password="root" />
everything is OK!
My app has jdbc drivres for both (mysql and postgres).
I am also uses postgresql with Java earlier I also facing the same problem,
I work around and found the solution, could you please try with adding below statement to bean "dataSource"
<property name="defaultAutoCommit" value="false"/>
I am using org.springframework.version -- >3.1.0.RELEASE and my datasource is like below
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" scope="prototype">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="username" value="test"/>
<property name="password" value="test123"/>
<property name="maxActive" value="100"/>
<property name="maxIdle" value="30"/>
<property name="maxWait" value="16000"/>
<property name="timeBetweenEvictionRunsMillis" value="30000"/>
<property name="minEvictableIdleTimeMillis" value="60000"/>
<property name="testOnBorrow" value="true"/>
<property name="validationQuery" value="SELECT 1"/>
</bean>
Here is below code to create jdbctemplate...
BasicDataSource bds = (BasicDataSource) ctx.getBean("dataSource");
bds.setUrl("jdbc:mysql://address=(protocol=tcp)(host=xx.xx.xx.xx)(port=3306 )/" + db + "?autoreconnect=true);
JdbcTemplate jt = new JdbcTemplate(bds);
I searched and this the url suggested to connect to IPv6 address. I am able to connect thro DriverManager.getConnection but not thro this datasource....Am i missing anything here
Exception
Caused by: java.net.UnknownHostException: address=(protocol=tcp)(host=xx.xx.xx.xx)
at java.net.InetAddress.getAllByName0(InetAddress.jav a:1215)
at java.net.InetAddress.getAllByName(InetAddress.java :1127)
at java.net.InetAddress.getAllByName(InetAddress.java :1063)
at com.mysql.jdbc.StandardSocketFactory.connect(Stand ardSocketFactory.java:243)
I am using Centos-6.2 x86_64, I have checked the /etc/hosts and everything looks fine.
I have following database configuration in a Spring project -
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${db.driver}" />
<property name="url" value="${db.jdbc.url}" />
<property name="username" value="${db.user}" />
<property name="password" value="${db.password}" />
<property name="maxActive" value="75" />
<property name="initialSize" value="10" />
<property name="testOnBorrow" value="true" />
<property name="validationQuery" value="SELECT 1" />
<property name="maxWait" value="10000"></property>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"
autowire="byName">
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>
The application runs for some time (30 mins to 2 hours, it varies) and after a while it starts to hang. i.e. The browser keeps on waiting for the server to respond. On checking the logs I found that the application is hung on a database query -
01/22 16:56:03 3024208 [http-bio-8080-exec-2] DEBUG DEBUG org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [SELECT * FROM mytable where id = ?]
The connection to the database is proper as I'm able to interact with it and run queries from commandline or mysql workbench.
What could be the source of the problem? At this point I'm totally at a loss as to which direction I should look in, since no exception gets thrown and there is no stacktrace. What approach would you use to attack this problem?
Have you tried creating a thread dump at the moment that your application hangs?
If you're on linux you could try to do:
$ kill -3 <pid>
The thread dump is written to the standard output. It may logged in the console or /logs/stdout or /logs/catalina.out.