Wednesday, June 25, 2008

How to Call Stored procedure in JAVA

For making Connection load sqljdbc.jar from Microsoft website.
Connection Provider Class.
package database;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class MSSQLDBConnection {
    private MSSQLDBConnection(){
    }
    static Connection conn=null;

    static{
       try {
         Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver") ;
      } catch (ClassNotFoundException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
    }

    public static Connection getConnection() throws SQLException, IOException {
      if(conn==null){
         conn = DriverManager.getConnection("jdbc:sqlserver://localhost;databaseName=TestDB","sa","sql");
      }
         return conn;
    }
}

Java Class for Calling STored procedure in MSSQL Database
package database.storedprocedure;

import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;

import database.MSSQLDBConnection;

public class CallStoredProcedure {

   /**
   * @param args
   */
   public static void main(String[] args) {
       Connection conn=null;
       try {
           conn=MSSQLDBConnection.getConnection();
       } catch (SQLException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       } catch (IOException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }

      CallableStatement callableStatement;
      try {
           callableStatement = conn.prepareCall("{ call spInsertEventContact(?,?,?,?,?,?) }");
           callableStatement.setInt(1, 12);
           callableStatement.setInt(2, 13);
           callableStatement.setString(3, "ASKER");
           callableStatement.setString(4, "ALI");
           callableStatement.setInt(5, 1);
           callableStatement.registerOutParameter(6, java.sql.Types.INTEGER);
           callableStatement.executeUpdate();
      } catch (SQLException e) {
           e.printStackTrace();
      }finally{
           try{
               conn.close();
           }catch (Exception ignore){}
      }

      System.out.println("Connection created");
   }
}
For database Connections please refer: IBM Universal database

How can i call Stored procedure which have Output Parameters

Stored Procedure structure in MSSQL is
ALTER Procedure InsertContact
(
@iEventID int,
@iClientID int,
@sLastName varchar(30),
@sFirstName varchar(30),
@iContactIDExisting int,
@iContactID int OUTPUT
)

I have tried with the following code
callableStatement = conn.prepareCall("{ call spInsertEventContact(?,?,?,?,?,?) }");
callableStatement.setInt(1, 1);
callableStatement.setInt(2, 1);
callableStatement.setString(3, "Name1");
callableStatement.setString(4, "Name2");
callableStatement.setInt(5, 10);
callableStatement.setInt(6, 0);
callableStatement.execute();

But getting the following Exception
com.microsoft.sqlserver.jdbc.SQLServerException: Transaction count after EXECUTE indicates that a COMMIT or ROLLBACK TRANSACTION statement is missing. Previous count = 1, current count = 0.

But here if i am sending only 5 arguments by discarding the sixth return value It is showing the Value is missing for @iContactID

I do tried with the following code using registerOutParameter in prepared Statement
callableStatement = conn.prepareCall("{ call spInsertEventContact(?,?,?,?,?,?) }");
callableStatement.setInt(1, 1);
callableStatement.setInt(2, 1);
callableStatement.setString(3, "Name1");
callableStatement.setString(4, "Name2");
callableStatement.setInt(5, 10);
callableStatement.registerOutParametert(6,java.sql.Types.INTEGER);
callableStatement.execute();

for more details:Please go through MSDN link :http://msdn.microsoft.com/en-us/library/ms378108.aspx

The following is the exception I am getting
12:57:31,507 ERROR [STDERR] com.microsoft.sqlserver.jdbc.SQLServerException: Transaction count after EXECUTE indicates that a COMMIT or ROLLBACK TRANSACTION statement is missing. Previous count = 1, current count = 0.
12:57:31,507 ERROR [STDERR] at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)
12:57:31,507 ERROR [STDERR] at com.microsoft.sqlserver.jdbc.IOBuffer.processPackets(Unknown Source)
12:57:31,507 ERROR [STDERR] at com.microsoft.sqlserver.jdbc.SQLServerStatement.sendExecute(Unknown Source)
12:57:31,507 ERROR [STDERR] at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteUpdate(Unknown Source)
12:57:31,507 ERROR [STDERR] at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(Unknown Source)
12:57:31,507 ERROR [STDERR] at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:251)
12:57:31,507 ERROR [STDERR] at org.domain.EMSeam2.session.EventActionBean.addEventContact(EventActionBean.java:104)
12:57:31,507 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
12:57:31,507 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
12:57:31,507 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
12:57:31,507 ERROR [STDERR] at java.lang.reflect.Method.invoke(Unknown Source)
12:57:31,507 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
12:57:31,507 ERROR [STDERR] at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
12:57:31,507 ERROR [STDERR] at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
12:57:31,507 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
12:57:31,507 ERROR [STDERR] at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
12:57:31,507 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
12:57:31,507 ERROR [STDERR] at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
12:57:31,507 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
12:57:31,507 ERROR [STDERR] at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
12:57:31,507 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
12:57:31,507 ERROR [STDERR] at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:26)
12:57:31,507 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
12:57:31,507 ERROR [STDERR] at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:27)
12:57:31,507 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
12:57:31,507 ERROR [STDERR] at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:106)
12:57:31,507 ERROR [STDERR] at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
12:57:31,507 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor152.invoke(Unknown Source)
12:57:31,507 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
12:57:31,507 ERROR [STDERR] at java.lang.reflect.Method.invoke(Unknown Source)
12:57:31,507 ERROR [STDERR] at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
12:57:31,507 ERROR [STDERR] at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
12:57:31,507 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
12:57:31,507 ERROR [STDERR] at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
12:57:31,507 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
12:57:31,507 ERROR [STDERR] at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
12:57:31,507 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
12:57:31,507 ERROR [STDERR] at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
12:57:31,507 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
12:57:31,507 ERROR [STDERR] at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
12:57:31,507 ERROR [STDERR] at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
12:57:31,507 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
12:57:31,507 ERROR [STDERR] at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:94)
12:57:31,507 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
12:57:31,507 ERROR [STDERR] at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:83)
12:57:31,507 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
12:57:31,507 ERROR [STDERR] at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
12:57:31,507 ERROR [STDERR] at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
12:57:31,507 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
12:57:31,507 ERROR [STDERR] at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
12:57:31,507 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
12:57:31,507 ERROR [STDERR] at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
12:57:31,507 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
12:57:31,522 ERROR [STDERR] at org.jboss.ejb3.stateful.StatefulContainer.localInvoke(StatefulContainer.java:204)
12:57:31,522 ERROR [STDERR] at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:117)
12:57:31,522 ERROR [STDERR] at $Proxy117.addEventContact(Unknown Source)
12:57:31,522 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
12:57:31,522 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
12:57:31,522 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
12:57:31,522 ERROR [STDERR] at java.lang.reflect.Method.invoke(Unknown Source)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.ejb.RemoveInterceptor.aroundInvoke(RemoveInterceptor.java:41)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.core.SynchronizationInterceptor.aroundInvoke(SynchronizationInterceptor.java:32)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:106)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
12:57:31,522 ERROR [STDERR] at org.javassist.tmp.java.lang.Object_$$_javassist_0.addEventContact(Object_$$_javassist_0.java)
12:57:31,522 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
12:57:31,522 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
12:57:31,522 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
12:57:31,522 ERROR [STDERR] at java.lang.reflect.Method.invoke(Unknown Source)
12:57:31,522 ERROR [STDERR] at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:328)
12:57:31,522 ERROR [STDERR] at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:341)
12:57:31,522 ERROR [STDERR] at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
12:57:31,522 ERROR [STDERR] at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
12:57:31,522 ERROR [STDERR] at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
12:57:31,522 ERROR [STDERR] at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
12:57:31,522 ERROR [STDERR] at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:69)
12:57:31,522 ERROR [STDERR] at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
12:57:31,522 ERROR [STDERR] at javax.faces.component.UICommand.broadcast(UICommand.java:383)
12:57:31,522 ERROR [STDERR] at org.ajax4jsf.component.AjaxActionComponent.broadcast(AjaxActionComponent.java:55)
12:57:31,522 ERROR [STDERR] at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:316)
12:57:31,522 ERROR [STDERR] at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:291)
12:57:31,522 ERROR [STDERR] at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:248)
12:57:31,522 ERROR [STDERR] at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:461)
12:57:31,522 ERROR [STDERR] at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
12:57:31,522 ERROR [STDERR] at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
12:57:31,522 ERROR [STDERR] at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
12:57:31,522 ERROR [STDERR] at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
12:57:31,522 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
12:57:31,522 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
12:57:31,522 ERROR [STDERR] at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:147)
12:57:31,522 ERROR [STDERR] at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:256)
12:57:31,522 ERROR [STDERR] at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:362)
12:57:31,522 ERROR [STDERR] at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:488)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
12:57:31,522 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
12:57:31,522 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
12:57:31,522 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
12:57:31,522 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
12:57:31,522 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
12:57:31,522 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
12:57:31,522 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
12:57:31,522 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
12:57:31,522 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
12:57:31,522 ERROR [STDERR] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
12:57:31,522 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
12:57:31,522 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
12:57:31,522 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
12:57:31,522 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
12:57:31,522 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
12:57:31,522 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
12:57:31,522 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
12:57:31,522 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
12:57:31,522 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
12:57:31,522 ERROR [STDERR] at java.lang.Thread.run(Unknown Source)
12:57:31,538 ERROR [SeamPhaseListener] uncaught exception
java.lang.IllegalStateException: Could not commit transaction
at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:592)
at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:325)
at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:226)
at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:184)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:280)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:147)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:256)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:362)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:488)
at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.transaction.RollbackException: [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] Can't commit because the transaction is in aborted state
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1394)
at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:140)
at org.jboss.seam.transaction.UTTransaction.commit(UTTransaction.java:52)
at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:582)

Friday, June 20, 2008

Cannot insert explicit value for identity column in table "Table Name" when IDENTITY_INSERT is set to OFF.

need to Add the following Annotations.
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@NotNull
@Column(name = "EventPhaseID", unique = true, nullable = false)

Also keep the Identity Specification of The primary Key to YES in the MSSQL Database Table properties

Wednesday, June 18, 2008

How to map Text datatype in MSSQL with Entity Bean in Hibernate

While generating the Entity with Hibernate Code generation tool it will providing String datatype.

To avoid the exception add @Lob Annotation with the getter method.

Monday, June 9, 2008

How to Convert String into CLOB and File object to BLOB Data Type

Here Hibernate is providing some Static methods to create this Data Types.
  1. Hibernate.createClob(String))
  2. Hibernate.createBlob(bytes))
In MSSQL Mapping of one TextArea In HTML to TEXT Data type in Data base table can be done through implementing one wrapper above the Entity bean.

Sunday, June 8, 2008

@JNDINAME Required Exception

This exception will come with the stateful bean in case of the absence of component.xml in the project.or the Datasource is not present in the project.

Wednesday, June 4, 2008

How to Call a Stored procedure usig JDBC Connection

After having the connection Object you can call any Stored Procedure using following Code.
Here spGetEventClient is the Stored procedure accepts one Argument.
try {
conn = dataSource.getConnection();
CallableStatement cs1 = conn.prepareCall("{call spGetEventClient(?)}");
cs1.setInt(1,13264);
ResultSet rs1 = cs1.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}