We're using Spring 2.5.4/Hibernate 3.2/Websphere Application Server 6.1.0.17. We've deployed the application on an AIX box. The next day when I come in, I try to log into the application. I get this exception on the page:
Error 500: Request processing failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: could not execute query; nested exception is org.hibernate.exception.JDBCConnectionException: could not execute query
I checked the System.Out logs and see further details. (Used pastebin because the log formatting was really screwing up the page layout)
The line of our code that is causing our exception is:
List loginList = getHibernateTemplate().find("from Login
where storeId =" + id + " and password ='" + password + "'");
We are wiring the connection in Spring's applicationContext.xml. We are aware that the connection on the AS400 drops at times (they may restart the system overnight--I'm not sure). However, we would preferably not want to open a new connection when we are wiring everything in the applicationContext.
This problem occurs irregardless of using a DataSource/JNDI or JDBC
Does anybody know of any settings to add to either Spring or Hibernate to check if the connection gets stale, and if so, drop it and create a new one? Or any other ideas to resolve this issue? Let me know if you need more information/code.
Much appreciated,
Chris
Update:
Checked out some posts on the Spring Community Forums and I've implemented my DataSource with commons-dbcp which has some properties like 'testWhileIdle' and 'validationQuery'. I'm going to leave the app running and check it again in the AM. Will post an update on the results.
Update#2:
Using dbcp-commons BasicDataSource seems to correct this issue, which appears to be a network problem. Websphere has pooled connections, and if there's a network issue on the AS400 side, it will try to use the connection it has, which it doesn't know is 'stale'. Using a validationQuery with a time interval is a cheap (but efficient) way to solve this problem--but there may be a better way on the Websphere side, under configuration. But, might as well not change what's not broken, so until this fails, it will probably be our solution going forward.
Ah, that's what I was gonna say... the problem must be solved in the connection pool, by validating connections before returning them. DBCP has validationQuery, and JBoss also has something similar; I'm sure Websphere must have something similar in its connection pool to validate connections before handing them out. Even if you don't use testWhileIdle, if the connection is found to be invalid, a new one is created and handed to you by the pool instead of the invalid one.
Related
I have a mule application that I can deploy on the server, but when I try to run a request (I'm using postman for this) I keep getting a timeout on a db query. I'm not sure what's causing the connection issue - the db is up and running and I can easily access it through IntelliJ. Running the query on the db (that fails when running from mule) gives instant results.
Does anyone know what I might be missing? I'm using mule standalone v3.9.3 which is the required one for the organization. I'm connected to the company's VPN and at first I thought maybe this was the issue, but other members are using the exact same mule server config, build is run from the same branch, and they're also connected to the same VPN gateway, and for them it works but I keep getting the timeout whatever I try :(
I've tried extending timeouts on the db and in the config according to some forum suggestions, but nothing works and I ran out of ideas what to try next and where to look for the issue, so all help would be greatly appreciated.
EDIT #1: I'm trying to setup the connection through AnyPointStudio hoping it will tell me more why the mule db connection is failing even though the db is accessible. But I encountered an issue - the connection itself is setup, but it seems like it doesn't recognize all schemas so I can't execute the query I need - is there any specific way I should configure the schema? I can't seem to find any option available for that
SOLUTION
It turned out to be an issue with a blocking port when an underlying http request was made out - not directly db related.
In AnyPoint I was finally able to connect as well but I needed to pass it the full name like [DB_NAME].[SCHEMA_NAME].[TABLE_NAME]
SOLUTION It turned out to be an issue with a blocking port when an underlying http request was made out - not directly db related. In AnyPoint I was finally able to connect as well but I needed to pass it the full name like [DB_NAME].[SCHEMA_NAME].[TABLE_NAME]
I have a requirement that retrieving a connection times out within specified time from the connection pool if there is any problem in the network. This should be handled through a java application.
Basically, want to give timeout to datasource.getConnection() method.
So after some research, I found setLoginTimeout(int seconds) method of DataSource has this functionality in order to notify if a database connection can not be made within the specified seconds.
I applied this on OracleConnectionPoolDataSource which is working fine, but for the Derby client driver it's giving exception as,
org.apache.derby.jdbc.ClientDriver does not have any such attribute loginTimeout.
Looking for your kind responses, please do let me know if there any other way to achieve this as per my requirement or anything I need to add/missing or any information related to this.
Server - Resin 3.0
finally able to achieve this by using c3p0 connection pooling instead of using datasource for derby.C3P0 has checkoutTimeout property which exactly works as per this requirement.
My java application does use DB Connection pooling. One of the functionality started failing today with this error:
[BEA][SQLServer JDBC Driver]No more data available to read
This doesn't occur daily. Once I restart my application server things look fine for some days and this error comes back again.
Anyone encountered this error? Reasons might vary, but I would like to know those various reasons to mitigate my issue.
Is it possible that the database or network connection has briefly had an outage? You might expect any currently open result sets then to become invalid with resulting errors.
I've never seen this particular error, but then I don't work with BEA or SQL Server, but a quick google does show other folks suggesting such a cause.
When you're using a connection pool, if you do get such a glitch, then all connections in teh pool become "stale" or invalid. My application server (WebSphere) has the option to discard the entire connection pool after particular errors are detected. The result then is that one unlucky request sees the error, but then subsequent requests get a new connection and recover. If you don't discard the whole pool then you get a failure as each stale connection is used and discarded.
I suggest you investigate to see a). whether your app server has such a capability b). how you application responds if the database is bounced, if this replicates the error then maybe you've found the cause.
I am attempting to add an Interbase connection pool to GlassFish v3 to use EJB 3.1 in a project. The glassfish log appears to be connecting to my database properly, it spits out all my table names and indices. However, I get an error
INFO: fetching database metadata
SEVERE: could not complete schema update
java.lang.NullPointerException
at interbase.interclient.ResultSet.local_Close(Unknown Source)
...
And when I ping the connection pool from within Glassfish I receive "Ping failed Exception - null".
I have the following properties set with my connectionpool:
resource type: javax.sql.DataSource
Datasource Classname: interbase.interclient.DataSource
portNumber: 3050
as well as my database info.
I can't seem to find information elsewhere. This question is similar but did not receive an answer.
thanks.
If the ping fails at the connection pool level then things are very likely not going to work. Any chances to use another database? If yes, really do it because Interbase seems to be an outdated product and I'm not very confident with the quality of available JDBC drivers (drivers listed in this page are all so old and dusty). It looks like time has been suspended with J2EE 1.3... If not, then maybe try another driver (the Firebird one for example).
Update: As pointed out by Craig in a comment, InterBase is maintained by Embarcadero and includes a Type 4 JDBC Driver. But, still, the Borland/CodeGear/Embarcadero products are IMHO on a dying trend.
I am trying to retrieve data form an Oracle database using jdbc (ojdbc14.jar). I have a limited number of concurrent connections when connecting to the database and these connections are managed by Websphere connection pool.
Sometimes when I make the call I see an UncategorizedSQLException exception thrown in my logs with one of the following oracle codes:
ORA-01012 (not logged in) exception
ORA-17410 (connection timed out, socket empty),
ORA-02396 exceeded maximum idle time, please connect again
Other times I get no exceptions and it works fine.
Anyone understand what might be happening here?
In Websphere I have my cache statement size set to 10. Not sure if it is relevant in this situation, when it looks like the connection is being dropped.
It looks like the database is deciding to drop the connection. It's a good idea to write your code in a way that doesn't require that a connection be held forever. A better choice is to have the program connect to the database, do its work, and disconnect. This eliminates the problem of the database deciding to disconnect the application due to inactivity/server overload/whatever, and the program needing to figure this out and make a reasonable stab at reconnecting.
I hope this helps.