JavaScript Caching
SQL SERVER 2000 with SP4
SEVERE: Standard SQL Exception Info for exception at level 0 - SQL State: 'HY000'; SQL Error Number: '0'; SQL Error Text: '[Microsoft][SQLServer 2000 Driver for JDBC]The DBMS returned an unspecified error.';[Microsoft][SQLServer 2000 Driver for JDBC]The DBMS returned an unspecified error. at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source) at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source) at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source) at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.executeUpdateInternal(Unknown Source) at com.microsoft.jdbc.base.BasePreparedStatement.executeUpdate(Unknown Source) at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)
Then the issue is with the jdbc driver, upgrade your driver to SQL 2005 server driver. This will resolve the problem. The jar will be sqljdbc.jar. If you are planning to use the latest jar of about 570KB this is good but you might hit the other error.
SEVERE: Standard SQL Exception Info for exception at level 0 - SQL State: '08S01'; SQL Error Number: '0'; SQL Error Text: 'The TDS protocol stream is not valid.';SEVERE: com.microsoft.sqlserver.jdbc.SQLServerException: The TDS protocol stream is not valid. at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.throwInvalidTDS(Unknown Source) at com.microsoft.sqlserver.jdbc.TDSReader.throwInvalidTDS(Unknown Source) at com.microsoft.sqlserver.jdbc.TDSParser.throwUnexpectedTokenException(Unknown Source) at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onRetValue(Unknown Source) at com.microsoft.sqlserver.jdbc.TDSParser.parse(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerResultSet$FetchBuffer.nextRow(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerResultSet.fetchBufferNext(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerResultSet.next(Unknown Source) at org.apache.tomcat.dbcp.dbcp.DelegatingResultSet.next(DelegatingResultSet.java:169)
To resolve this download and use the Microsoft SQL Server 2005 JDBC Driver 1.2 or 1.1 from
http://msdn.microsoft.com/data/jdbc
SQL SERVER database and user
3) Select the appropriate roles for the user
5) Now open the database you want the user just created to access. Select the user and in the right window right click and select New Database User.
Now when you try to write a java application to connect to this database, you may see the error/exception as
This can be solved by following the steps below.
First try the telnet
1. Make sure that SQL Server is set to mixed authentication. To do this, open enterprise manager, right click on server registered on there, go to security tab and select SQL Server and Windows Authentication.
2. Go to the general tab and click the network configuration button. Enable TCP/IP. Click properties to change the default port (1433).
3. Add an SQL Server login account (NOT a WINDOWS account (see 1)). You can also use your sa account.
Happy SQLing..
com.ibm.websphere.ce.cm.ObjectClosedException: DSRA9110E: ResultSet is closed.
There are many reasons for why we get this error and so do equal number of solutions. I have scenerio where the result set is shared by the class APIs and started encountering this error. One of the good solutions I implemented is setting the resultSetHoldability property from 2 to 1 (Please see the documentations of WebSphere for furthur details.) After changing this property value please restart the server for the property to reset. This is one of the GREATEST APP SERVER.
The stacktrace look something like this.
com.ibm.websphere.ce.cm.ObjectClosedException: DSRA9110E: ResultSet is closed.
at com.ibm.ws.rsadapter.jdbc.WSJdbcResultSet.runtimeXIfNotClosed(WSJdbcResultSet.java:2691)
at com.ibm.ws.rsadapter.jdbc.WSJdbcResultSet.next(WSJdbcResultSet.java:2478)
....
....
....
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:615)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy7.generateReport(Unknown Source)
.....
.....
at org.springframework.scheduling.commonj.DelegatingWork.run(DelegatingWork.java:61)
at com.ibm.ws.asynchbeans.J2EEContext.run(J2EEContext.java:1112)
at com.ibm.ws.asynchbeans.WorkWithExecutionContextImpl.go(WorkWithExecutionContextImpl.java:195)
at com.ibm.ws.asynchbeans.CJWorkItemImpl.run(CJWorkItemImpl.java:187)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1510)
The one of the solution for this is go to the admin console and select JDBC->Data Sources->Custom Properties->resultSetHoldability and change its value from 2 to 1.
Setup and Teardown
Now lets come to the Spring, after the constructor is used to create the object of the class, we can configure a method to be called by the spring container (init() is called by the servlet container). After the constructor is done with its defined job and we need some other peice of code to invoked which might be used once in the life cycle of the object, we can configure this method as the init-method for this bean.
I found this very useful when we had a different encryption and decription keys for the objects and is independent to the intentions of the bean creation. So I configure this init-method and destroy-method to achieve this. Here is the typical code for the same.
package test.spring.injection;
|
<?xml version="1.0" encoding="UTF-8"?>
<beans> <beans> <bean id="customInit" class="test.spring.injection.CustomInit" init-method="setEncryptionKey" destroy-method="broadcastEncryptionKey" /> </beans> |
The best approach then the above would be to implement the InitializingBean and DisposableBean. Now override the afterPropertiesSet() [implement init-method logic here] and destroy() [implement the destroy-method logic here]. These are the bean lifecycle API's
Spring DI (factory method)
Now that we understand the Spring Dependency Injection and the singleton implementation, and we also know how to configured the class as bean in spring definition file which has the constructor either the default or overridden. Let’s understand how to configure the singleton class in spring.
To highlight the scenario singleton does not have a public constructor (which means new keyword cannot be used to instantiate the object of this class) and has a public static getInstance method to get the instance of the class.
Spring provided the way to configure such classes as beans through the factory methods. Here we will configure the factory-method which is responsible to return the object of the class.
The singleton class would be
The singleton I read in the "Spring in Action" book
package test.patterns;
public class SingltonInner {
private SingltonInner(){}
private static class InnerSingltonInstance{
static SingltonInner singlton = new SingltonInner();
}
public static SingltonInner getInstance(){
return InnerSingltonInstance.singlton;
}
public String getMessage(String name){
return "Hello " + name;
}
}
Java2html
The class using the Singleton
|
Java2html
|
The definition of the beans is in this XML file.
<?xml version="1.0" encoding="UTF-8"?>
<beans> <bean id="factoryInjection" class="test.spring.injection.FactoryInjection"> <property name="singleton"> <ref bean="singltonInner"/> </property> </bean> <bean id="singltonInner" class="test.patterns.SingltonInner" factory-method="getInstance"/> </beans> |
Singlton
- Make the default constructor private.
- Create a static and public getInstance method returning the object of the singleton class.
- Make the class final.
- Implement the Cloneable interface.
- Override the clone method to throw the CloneNotSupportedException.
package test.patterns; |
used Java2html to format the code |
The other good type I read in the "Spring in Action" book
package test.patterns;
public class SingltonInner {
private SingltonInner(){}
private static class InnerSingltonInstance{
static SingltonInner singlton = new SingltonInner();
}
public static SingltonInner getInstance(){
return InnerSingltonInstance.singlton;
}
}
Java2html