I have created a Spring web application for reading ms access large database file. Sometime this file is repaired due to large size. Before compacting database file all open sessions are closed. After closing session and repairing database when we connect to database from spring web application then i get the following error.
HTTP Status 500 - Request processing failed; nested exception is
org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback;
SQL [select [DateTimeEntered],[GoodWeight],[MachineSpeed],[GradeCode],[RejectedWeight]
from [tblMachineProduction] where [DateTimeEntered] between ? and ? order by
[DateTimeEntered]]; [Microsoft][ODBC Microsoft Access Driver] Your network access was
interrupted. To continue, close the database, and then open it again.; nested exception
is java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Your network access
was interrupted. To continue, close the database, and then open it again.
How to hanlde this exception or how to reload/ initialize data source.
Spring code is here:-
<bean id="dataSource" scope="prototype" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.database.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="testOnBorrow" value="true"/>
<property name="testOnReturn" value="true"/>
<property name="testWhileIdle" value="true"/>
</bean>
Related
My application was running WebSphere where all the connection pool setting was done in WAS console data source and connection pool was handled by IBM WAS. but now i am removing the WAS server and moving to tomcat and using the below connection to connect with Teradatadata source. but getting below error. is there anything i am missing here? or what is properway to create data source using spring xml bean which manage the connections.
ERROR
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: Connection was closed in SingleConnectionDataSource. Check that user code checks shouldClose() before closing Connections, or set 'suppressClose' to 'true'
CODE
<property name="driverClassName" value="com.teradata.jdbc.TeraDriver"/>
<property name="url" >
<util:constant static-field="MYCLASS._DB_HOST"/>
</property>
<property name="username">
<util:constant static-field="MYCLASS._DB_USER"/>
</property>
<property name="password">
<util:constant static-field="MYCLASS.DB_PWD"/>
</property>
<property name="suppressClose" value="true" />
</bean>```
When I run Spring batch to process more than 100 records, I am get following error,
"Listener Refused the connection with the following error: ORA-12516,
TNS:Listener could not available handler with matching protocol stack".
But when I run the batch to process less than 50 records, it works fine.
In my batch's before step of my reader, I query DB to get records.
e.g. If I get 100 records from DB, Using Loop, I extract a particular field from each record and using the particular fields i will query to another table. So the second query run for 100 times inside the for loop.
In Logs, I can see the batch runs for a while (queries some records inside for loop) and then it throws the error.
Please help me to solve this.
OnlyGod Team -
Oracle database server's value for "PROCESSES" has been configured too low
you can resolve it by steps
Launch 'SQL Plus'
Logon as 'system'
Type the following command (to check that the database is using spfile):
show parameter spfile
Assuming that it shows that you ARE using spfile, then type the following command:
alter system set PROCESSES=300 scope = spfile
Obtain some downtime (nobody using the databases) and restart the Oracle database server (or simply the relevant Oracle database) or you can edit it in notepad++
Changed my data source bean from
<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>
to this
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${database.driverClassName}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.username}" />
<property name="password" value="${database.password}" />
<property name="connectionProperties" value="initialSize=1,maxTotal=10" />
</bean>
when i am trying to connect to a test db which settings as per shown, i am faced all the errors as per mentioned.
most of the config is taken from working production environment but i am not able to connect to my test db.
i have tried various methods and it just fails to run properly.
Im able to connect test db via other methods such as PLSQL developer or SQLPLUS.
The errors i am getting in a bunch are :
org.hibernate.exception.GenericJDBCException: Cannot open connection
....
....
....
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
....
....
....
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1422)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:606)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:526)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:756) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:683)
this is my config file for hibernate :
<session-factory>
<property name="hibernate.connection.url">jdbc:oracle:thin:#ipaddress:1521:dbname</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.connection.password">password</property>
<property name="connection.autoReconnect">true</property>
<property name="connection.autoReconnectForPools">true</property>
<property name="connection.is-connection-validation-required">true</property>
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.max_size">1</property>
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.timeout">50000</property>
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.validate">false</property>
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<mapping resource etc>
</session-factory>
Can anyone help me on this issue?
It happen for many reason like
The database configuration details you have entered are incorrect or have changed, e.g. the database name or database username/password for your Confluence database.
1)The URL for the database is incorrect.
2)The database server is not running. If your database server is down, restart it and check the logs to see why it had failed or stopped.
3)The network is down (or there is a firewall in between confluence and the database server which is interfering) and the connection to the database cannot be established.
4)Your database password has expired.
5)Check your driver,if its present or not in your class-path.
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)
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.