/*
 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

/*
 * @(#)callStmtClient22.java	1.6 02/01/12
 */

package com.sun.cts.tests.jdbc.ee.callStmt.callStmt22;

import java.io.*;
import java.util.*;
import java.math.*;

import java.sql.*;
import javax.sql.*;

import com.sun.cts.util.*;
import com.sun.cts.porting.*;
import com.sun.cts.harness.*;

import java.rmi.RemoteException;

import javasoft.sqe.javatest.Status;
import com.sun.cts.tests.jdbc.ee.common.*;


// Merant DataSource class
//import com.merant.sequelink.jdbcx.datasource.*;


/**
 * The callStmtClient22 class tests methods of CallableStatement interface (to check the
 * Support for IN, OUT and INOUT parameters of Stored Procedure) using
 * Sun's J2EE Reference Implementation.
 * @author
 * @version 1.7, 06/16/99
 */

public class callStmtClient22 extends ServiceEETest implements Serializable
{
	private static final String testName = "jdbc.ee.callStmt.callStmt22";

	//Naming specific member variables
	private CTSNamingContextInterface jc = null;

	//Harness requirements

	private transient Connection conn = null;
	private DataSource ds1 = null;
	private rsSchema rsSch=null;
	private	String drManager=null;
	private Properties sqlp = null;
	private	CallableStatement cstmt = null;

	/* Run test in standalone mode */
	public static void main(String[] args)
	{
		callStmtClient22 theTests = new callStmtClient22();
		Status s=theTests.run(args, System.out, System.err);
		s.exit();
	}

	/*  Test setup: */
	/*
	 *   @class.setup_props: Driver, the Driver name;
	 *			db1, the database name with url;
	 *			user1, the database user name;
	 *			password1, the database password;
	 *			db2, the database name with url;
	 *			user2, the database user name;
	 *			password2, the database password;
	 *			DriverManager, flag for DriverManager;
	 *			ptable, the primary table;
	 *			ftable, the foreign table;
	 *			cofSize, the initial size of the ptable;
	 *			cofTypeSize, the initial size of the ftable;
	 *			binarySize, size of binary data type;
	 *			varbinarySize, size of varbinary data type;
	 *			longvarbinarySize, size of longvarbinary data type;
	 *  @class.testArgs:     -ap ctssql.stmt
	 */
	public void setup(String[] args, Properties p) throws Fault
	{
		try
		{
			try
			{
				drManager = p.getProperty("DriverManager","");
				if (drManager.length() == 0)
					throw new Fault("Invalid DriverManager Name");
				sqlp=p;

				if(drManager.equals("yes"))
				{
					logMsg("Using DriverManager");
					DriverManagerConnection dmCon = new DriverManagerConnection();
					conn = dmCon.getConnection(p);
				}
				else
				{
					logMsg("Using DataSource");
					DataSourceConnection dsCon = new DataSourceConnection();
					conn = dsCon.getConnection(p);
				}
				rsSch = new rsSchema();
			}
			catch(SQLException ex)
			{
				logErr("SQL Exception : " + ex.getMessage());
			}
		}
		catch  ( Exception e )
		{
			logErr("Setup Failed!");
			TestUtil.printStackTrace(e);
		}
	}



	/*
	 * @testName:         testRegisterOutParameter49
	 * @assertion:        A CallableStatement object provides a way to call stored procedures
	 *                    in a standard way for all RDBMSs.  It can take variable number of
	 *                    parameters used for input (IN parameters), output (OUT parameters)
	 *                    or both (INOUT parameters).  (See section 9.1 of JDBC 2.0 API
	 *                    Reference & Tutorial, Second Edition)
	 *
	 *                    The drivers must provide full support for CallableStatement methods
	 *                    that apply to SQL92 types.  All parameter types (IN, OUT, INOUT)
	 *                    must be supported (See section 6.2.2.3 of Java2 Platform Enterprise
	 *                    Edition (J2EE) specification v 1.2)
	 *
	 *                    The registerOutParameter(int parameterIndex, int jdbcType) method
	 *                    registers the OUT parameter in ordinal position parameterIndex to the
	 *                    JDBC type jdbcType.  All OUT parameters should be registered before a
	 *                    stored procedure is executed. The JDBC type specified by sqlType for an
	 *                    OUT parameter determines the Java type that must be used in the get
	 *                    method to read the value of that parameter. If the JDBC type expected to
	 *                    be returned to this output parameter is specific to this particular
	 *                    database, sqlType should be java.sql.Types.OTHER. The method
	 *                    getObject(int) retrieves the value.  (See JDK 1.2.2 API Specification)
	 *
	 * @test_Strategy:    Get a CallableStatement object from the connection to the database.
	 *                    execute the stored procedure and call the setObject() method to
	 *                    set Date value in null column of Date table and call
	 *                    registerOutParameter(int parameterIndex, int jdbcType) method
	 *                    and call getDate method.  It should return a Date object
	 *                    that is been set.  (Note: This test case also checks the support
	 *                    for INOUT parameter in Stored Procedure)
	 *
	 */
	public void testRegisterOutParameter49() throws Fault
	{
		try
		{
			rsSch.createTab("Date_Tab",sqlp,conn);

			String sMfgDate = rsSch.extractVal("Date_Tab",1,sqlp,conn);
			sMfgDate =sMfgDate.substring(sMfgDate.indexOf('\'')+1,sMfgDate.lastIndexOf('\''));
			java.sql.Date mfgDate =java.sql.Date.valueOf(sMfgDate);

			// get the CallableStatement object
			cstmt = conn.prepareCall("{call Date_Io_Null(?)}");
			cstmt.setObject(1,mfgDate);

			//register the output parameters
			cstmt.registerOutParameter(1,java.sql.Types.DATE);

			//execute the procedure
			cstmt.executeUpdate();
			logMsg("Calling CallableStatement.getObject(NULL_VAL)");
			//invoke getObject method
			java.sql.Date oRetVal = (java.sql.Date) cstmt.getObject(1);
			logMsg("Returned Value from ctssql.stmt:" +mfgDate);
			logMsg("Value returned from table :" +oRetVal);

			if(mfgDate.equals(oRetVal))
				logMsg("registerOutParameter registers the OUT parameter");
			else
			{
				logErr("registerOutParameter does not register the OUT parameter");
				throw new Fault("Call to registerOutParameter is Failed!");
			}
		}
		catch(SQLException sqle)
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to registerOutParameter is Failed!");
		}
		catch ( Exception e )
		{
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to registerOutParameter is Failed!", e);
		}
		finally
		{
			try
			{
				if(cstmt != null)
				{
					cstmt.close();
					cstmt=null;
				}
				rsSch.dropTab("Date_Tab",conn);

			}
			catch (Exception e) {}
		}
	}

	/*
	 * @testName:         testRegisterOutParameter50
	 * @assertion:        A CallableStatement object provides a way to call stored procedures
	 *                    in a standard way for all RDBMSs.  It can take variable number of
	 *                    parameters used for input (IN parameters), output (OUT parameters)
	 *                    or both (INOUT parameters).  (See section 9.1 of JDBC 2.0 API
	 *                    Reference & Tutorial, Second Edition)
	 *
	 *                    The drivers must provide full support for CallableStatement methods
	 *                    that apply to SQL92 types.  All parameter types (IN, OUT, INOUT)
	 *                    must be supported (See section 6.2.2.3 of Java2 Platform Enterprise
	 *                    Edition (J2EE) specification v 1.2)
	 *
	 *                    The registerOutParameter(int parameterIndex, int jdbcType) method
	 *                    registers the OUT parameter in ordinal position parameterIndex to the
	 *                    JDBC type jdbcType.  All OUT parameters should be registered before a
	 *                    stored procedure is executed. The JDBC type specified by sqlType for an
	 *                    OUT parameter determines the Java type that must be used in the get
	 *                    method to read the value of that parameter. If the JDBC type expected to
	 *                    be returned to this output parameter is specific to this particular
	 *                    database, sqlType should be java.sql.Types.OTHER. The method
	 *                    getObject(int) retrieves the value.  (See JDK 1.2.2 API Specification)
	 *
	 * @test_Strategy:    Get a CallableStatement object from the connection to the database.
	 *                    execute the stored procedure and call the setObject() method to
	 *                    set Time Object in null column of Time table and call
	 *                    registerOutParameter(int parameterIndex, int jdbcType) method
	 *                    and call getTime method.  It should return a Time object
	 *                    that is been set.  (Note: This test case also checks the support
	 *                    for INOUT parameter in Stored Procedure)
	 *
	 */
	public void testRegisterOutParameter50() throws Fault
	{
		String sBrkTime = null;
		java.sql.Time brkTime = null;
		try
		{
			rsSch.createTab("Time_Tab",sqlp,conn);

			sBrkTime = rsSch.extractVal("Time_Tab",1,sqlp,conn);
			sBrkTime = sBrkTime.substring(sBrkTime.indexOf('\'')+1,sBrkTime.lastIndexOf('\''));
			brkTime = java.sql.Time.valueOf(sBrkTime);

			// get the CallableStatement object
			cstmt = conn.prepareCall("{call Time_Io_Null(?)}");
			cstmt.setObject(1,brkTime);

			//register the output parameters
			cstmt.registerOutParameter(1,java.sql.Types.TIME);

			//execute the procedure
			cstmt.executeUpdate();
			logMsg("Calling CallableStatement.getObject(NULL_VAL)");
			//invoke getObject method
			java.util.Date dRetVal = (java.util.Date) cstmt.getObject(1);
			long lDate = dRetVal.getTime();
			java.sql.Time oRetVal = new java.sql.Time(lDate);
			logMsg("Returned Value from ctssql.stmt:" +brkTime);
			logMsg("Value returned from table :" +oRetVal);

			if(brkTime.toString().trim().equals(oRetVal.toString().trim()))
				logMsg("registerOutParameter registers the OUT parameter");
			else
			{
				logErr("registerOutParameter does not register the OUT parameter");
				throw new Fault("Call to registerOutParameter is Failed!");
			}
		}
		catch(SQLException sqle)
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to registerOutParameter is Failed!");
		}
		catch ( Exception e )
		{
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to registerOutParameter is Failed!", e);
		}
		finally
		{
			try
			{
				if(cstmt != null)
				{
					cstmt.close();
					cstmt=null;
				}
				rsSch.dropTab("Time_Tab",conn);

			}
			catch (Exception e) {}
		}
	}

	/*
	 * @testName:         testRegisterOutParameter51
	 * @assertion:        A CallableStatement object provides a way to call stored procedures
	 *                    in a standard way for all RDBMSs.  It can take variable number of
	 *                    parameters used for input (IN parameters), output (OUT parameters)
	 *                    or both (INOUT parameters).  (See section 9.1 of JDBC 2.0 API
	 *                    Reference & Tutorial, Second Edition)
	 *
	 *                    The drivers must provide full support for CallableStatement methods
	 *                    that apply to SQL92 types.  All parameter types (IN, OUT, INOUT)
	 *                    must be supported (See section 6.2.2.3 of Java2 Platform Enterprise
	 *                    Edition (J2EE) specification v 1.2)
	 *
	 *                    The registerOutParameter(int parameterIndex, int jdbcType) method
	 *                    registers the OUT parameter in ordinal position parameterIndex to the
	 *                    JDBC type jdbcType.  All OUT parameters should be registered before a
	 *                    stored procedure is executed. The JDBC type specified by sqlType for an
	 *                    OUT parameter determines the Java type that must be used in the get
	 *                    method to read the value of that parameter. If the JDBC type expected to
	 *                    be returned to this output parameter is specific to this particular
	 *                    database, sqlType should be java.sql.Types.OTHER. The method
	 *                    getObject(int) retrieves the value.  (See JDK 1.2.2 API Specification)
	 *
	 * @test_Strategy:    Get a CallableStatement object from the connection to the database.
	 *                    execute the stored procedure and call the setObject() method to
	 *                    set Timestamp value in null column of Timestamp table and call
	 *                    registerOutParameter(int parameterIndex, int jdbcType) method
	 *                    and call getTimestamp method.  It should return a Timestamp object
	 *                    that is been set.  (Note: This test case also checks the support
	 *                    for INOUT parameter in Stored Procedure)
	 *
	 */
	public void testRegisterOutParameter51() throws Fault
	{
		try
		{
			rsSch.createTab("Timestamp_Tab",sqlp,conn);

			String sInTime = rsSch.extractVal("Timestamp_Tab",1,sqlp,conn);
			sInTime=sInTime.substring(sInTime.indexOf('\'')+1,sInTime.lastIndexOf('\''));
			java.sql.Timestamp inTimestamp=Timestamp.valueOf(sInTime);
			logMsg("Timestamp value to be updated   :   " + inTimestamp);

			// get the CallableStatement object
			cstmt = conn.prepareCall("{call Timestamp_Io_Null(?)}");
			cstmt.setObject(1,inTimestamp);

			//register the output parameters
			cstmt.registerOutParameter(1,java.sql.Types.TIMESTAMP);

			//execute the procedure
			cstmt.executeUpdate();
			logMsg("Calling CallableStatement.getObject(NULL_VAL)");
			//invoke getObject method
			java.sql.Timestamp oRetVal = (java.sql.Timestamp) cstmt.getObject(1);
			logMsg("Returned Value from ctssql.stmt:" +inTimestamp);
			logMsg("Value returned from table :" +oRetVal);

			if(inTimestamp.compareTo(oRetVal)==0)
				logMsg("registerOutParameter registers the OUT parameter");
			else
			{
				logErr("registerOutParameter does not register the OUT parameter");
				throw new Fault("Call to registerOutParameter is Failed!");
			}
		}
		catch(SQLException sqle)
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to registerOutParameter is Failed!");
		}
		catch ( Exception e )
		{
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to registerOutParameter is Failed!", e);
		}
		finally
		{
			try
			{
				if(cstmt != null)
				{
					cstmt.close();
					cstmt=null;
				}
				rsSch.dropTab("Timestamp_Tab",conn);

			}
			catch (Exception e) {}
		}
	}


	/*
	 * @testName:         testRegisterOutParameter52
	 * @assertion:        A CallableStatement object provides a way to call stored procedures
	 *                    in a standard way for all RDBMSs.  It can take variable number of
	 *                    parameters used for input (IN parameters), output (OUT parameters)
	 *                    or both (INOUT parameters).  (See section 9.1 of JDBC 2.0 API
	 *                    Reference & Tutorial, Second Edition)
	 *
	 *                    The drivers must provide full support for CallableStatement methods
	 *                    that apply to SQL92 types.  All parameter types (IN, OUT, INOUT)
	 *                    must be supported (See section 6.2.2.3 of Java2 Platform Enterprise
	 *                    Edition (J2EE) specification v 1.2)
	 *
	 *                    The registerOutParameter(int parameterIndex, int jdbcType) method
	 *                    registers the OUT parameter in ordinal position parameterIndex to the
	 *                    JDBC type jdbcType.  All OUT parameters should be registered before a
	 *                    stored procedure is executed. The JDBC type specified by sqlType for an
	 *                    OUT parameter determines the Java type that must be used in the get
	 *                    method to read the value of that parameter. If the JDBC type expected to
	 *                    be returned to this output parameter is specific to this particular
	 *                    database, sqlType should be java.sql.Types.OTHER. The method
	 *                    getObject(int) retrieves the value.  (See JDK 1.2.2 API Specification)
	 *
	 * @test_Strategy:    Get a CallableStatement object from the connection to the database.
	 *                    execute the stored procedure and call the setObject() method to
	 *                    set Byte Array object in Binary table and call
	 *                    registerOutParameter(int parameterIndex, int jdbcType) method
	 *                    and call getBytes method.  It should return a Byte Array object
	 *                    that is been set.  (Note: This test case also checks the support
	 *                    for INOUT parameter in Stored Procedure)
	 *
	 */
	public void testRegisterOutParameter52() throws Fault
	{
		byte retByteArr[]=null;
		boolean byteArrFlag=false;
		String binarySize=null;

		try
		{
			rsSch.createTab("Binary_Tab",sqlp,conn);

			binarySize = sqlp.getProperty("binarySize");
			logMsg("Binary Table Size : " + binarySize);

			int bytearrsize = Integer.parseInt(binarySize);
			logMsg("Binary Size : " + bytearrsize);

			byte[] bytearr=new byte[bytearrsize];
			String sbyteval=null;

			// to get the bytearray value
			for (int count=0;count<bytearrsize;count++)
			{
				sbyteval=Integer.toString(count%255);
				bytearr[count]=Byte.parseByte(sbyteval);
			}

			// get the CallableStatement object
			cstmt = conn.prepareCall("{call Binary_Proc_Io(?)}");
			cstmt.setObject(1,bytearr);

			//register the output parameters
			cstmt.registerOutParameter(1,java.sql.Types.BINARY);

			//execute the procedure
			cstmt.executeUpdate();
			logMsg("Calling CallableStatement.getObject(NULL_VAL)");
			//invoke getObject method
			retByteArr = (byte[]) cstmt.getObject(1);

			for(int i=0;i<bytearrsize;i++)
			{
				if (retByteArr[i]!=bytearr[i])
				{
					logErr("registerOutParameter does not register the OUT parameter");
					throw new Fault("Call to registerOutParameter Method is Failed!");
				}
			}
			logMsg("registerOutParameter registers the OUT parameter");
		}
		catch(SQLException sqle)
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to registerOutParameter is Failed!");
		}
		catch ( Exception e )
		{
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to registerOutParameter is Failed!", e);
		}
		finally
		{
			try
			{
				if(cstmt != null)
				{
					cstmt.close();
					cstmt=null;
				}
				rsSch.dropTab("Binary_Tab",conn);

			}
			catch (Exception e) {}
		}
	}

	/*
	 * @testName:         testRegisterOutParameter53
	 * @assertion:        A CallableStatement object provides a way to call stored procedures
	 *                    in a standard way for all RDBMSs.  It can take variable number of
	 *                    parameters used for input (IN parameters), output (OUT parameters)
	 *                    or both (INOUT parameters).  (See section 9.1 of JDBC 2.0 API
	 *                    Reference & Tutorial, Second Edition)
	 *
	 *                    The drivers must provide full support for CallableStatement methods
	 *                    that apply to SQL92 types.  All parameter types (IN, OUT, INOUT)
	 *                    must be supported (See section 6.2.2.3 of Java2 Platform Enterprise
	 *                    Edition (J2EE) specification v 1.2)
	 *
	 *                    The registerOutParameter(int parameterIndex, int jdbcType) method
	 *                    registers the OUT parameter in ordinal position parameterIndex to the
	 *                    JDBC type jdbcType.  All OUT parameters should be registered before a
	 *                    stored procedure is executed. The JDBC type specified by sqlType for an
	 *                    OUT parameter determines the Java type that must be used in the get
	 *                    method to read the value of that parameter. If the JDBC type expected to
	 *                    be returned to this output parameter is specific to this particular
	 *                    database, sqlType should be java.sql.Types.OTHER. The method
	 *                    getObject(int) retrieves the value.  (See JDK 1.2.2 API Specification)
	 *
	 * @test_Strategy:    Get a CallableStatement object from the connection to the database.
	 *                    execute the stored procedure and call the setObject() method to
	 *                    set Byte Array object in Varbinary table and call
	 *                    registerOutParameter(int parameterIndex, int jdbcType) method
	 *                    and call getBytes method.  It should return a Byte Array object
	 *                    that is been set.  (Note: This test case also checks the support
	 *                    for INOUT parameter in Stored Procedure)
	 *
	 */
	public void testRegisterOutParameter53() throws Fault
	{
		byte retByteArr[]=null;
		boolean byteArrFlag=false;
		String varbinarySize=null;

		try
		{
			rsSch.createTab("Varbinary_Tab",sqlp,conn);

			varbinarySize = sqlp.getProperty("varbinarySize");
			logMsg("Varbinary Table Size : " + varbinarySize);

			int bytearrsize = Integer.parseInt(varbinarySize);
			logMsg("Varbinary Size : " + bytearrsize);

			byte[] bytearr=new byte[bytearrsize];
			String sbyteval=null;

			// to get the bytearray value
			for (int count=0;count<bytearrsize;count++)
			{
				sbyteval=Integer.toString(count%255);
				bytearr[count]=Byte.parseByte(sbyteval);
			}

			// get the CallableStatement object
			cstmt = conn.prepareCall("{call Varbinary_Proc_Io(?)}");
			cstmt.setObject(1,bytearr);

			//register the output parameters
			cstmt.registerOutParameter(1,java.sql.Types.VARBINARY);

			//execute the procedure
			cstmt.executeUpdate();
			logMsg("Calling CallableStatement.getObject(NULL_VAL)");
			//invoke getObject method
			retByteArr = (byte[]) cstmt.getObject(1);

			for(int i=0;i<bytearrsize;i++)
			{
				if (retByteArr[i]!=bytearr[i])
				{
					logErr("registerOutParameter does not register the OUT parameter");
					throw new Fault("Call to registerOutParameter Method is Failed!");
				}
			}
			logMsg("registerOutParameter registers the OUT parameter");
		}
		catch(SQLException sqle)
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to registerOutParameter is Failed!");
		}
		catch ( Exception e )
		{
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to registerOutParameter is Failed!", e);
		}
		finally
		{
			try
			{
				if(cstmt != null)
				{
					cstmt.close();
					cstmt=null;
				}
				rsSch.dropTab("Varbinary_Tab",conn);

			}
			catch (Exception e) {}
		}
	}

	/*
	 * @testName:         testRegisterOutParameter54
	 * @assertion:        A CallableStatement object provides a way to call stored procedures
	 *                    in a standard way for all RDBMSs.  It can take variable number of
	 *                    parameters used for input (IN parameters), output (OUT parameters)
	 *                    or both (INOUT parameters).  (See section 9.1 of JDBC 2.0 API
	 *                    Reference & Tutorial, Second Edition)
	 *
	 *                    The drivers must provide full support for CallableStatement methods
	 *                    that apply to SQL92 types.  All parameter types (IN, OUT, INOUT)
	 *                    must be supported (See section 6.2.2.3 of Java2 Platform Enterprise
	 *                    Edition (J2EE) specification v 1.2)
	 *
	 *                    The registerOutParameter(int parameterIndex, int jdbcType) method
	 *                    registers the OUT parameter in ordinal position parameterIndex to the
	 *                    JDBC type jdbcType.  All OUT parameters should be registered before a
	 *                    stored procedure is executed. The JDBC type specified by sqlType for an
	 *                    OUT parameter determines the Java type that must be used in the get
	 *                    method to read the value of that parameter. If the JDBC type expected to
	 *                    be returned to this output parameter is specific to this particular
	 *                    database, sqlType should be java.sql.Types.OTHER. The method
	 *                    getObject(int) retrieves the value.  (See JDK 1.2.2 API Specification)
	 *
	 * @test_Strategy:    Get a CallableStatement object from the connection to the database.
	 *                    execute the stored procedure and call the setObject() method to
	 *                    set Byte Array object in Longvarbinary table and call
	 *                    registerOutParameter(int parameterIndex, int jdbcType) method
	 *                    and call getBytes method.  It should return a Byte Array object
	 *                    that is been set.  (Note: This test case also checks the support
	 *                    for INOUT parameter in Stored Procedure)
	 *
	 */
	public void testRegisterOutParameter54() throws Fault
	{
		byte retByteArr[]=null;
		boolean byteArrFlag=false;
		String longvarbinarySize=null;

		try
		{
			rsSch.createTab("Longvarbinary_Tab",sqlp,conn);

			longvarbinarySize = sqlp.getProperty("longvarbinarySize");
			logMsg("Longvarbinary Table Size : " + longvarbinarySize);

			int bytearrsize = Integer.parseInt(longvarbinarySize);
			logMsg("Varbinary Size : " + bytearrsize);

			byte[] bytearr=new byte[bytearrsize];
			String sbyteval=null;

			// to get the bytearray value
			for (int count=0;count<bytearrsize;count++)
			{
				sbyteval=Integer.toString(count%255);
				bytearr[count]=Byte.parseByte(sbyteval);
			}

			// get the CallableStatement object
			cstmt = conn.prepareCall("{call Longvarbinary_Io(?)}");
			cstmt.setObject(1,bytearr);

			//register the output parameters
			cstmt.registerOutParameter(1,java.sql.Types.LONGVARBINARY);

			//execute the procedure
			cstmt.executeUpdate();
			logMsg("Calling CallableStatement.getObject()");
			//invoke getObject method
			retByteArr = (byte[]) cstmt.getObject(1);

			for(int i=0;i<bytearrsize;i++)
			{
				if (retByteArr[i]!=bytearr[i])
				{
					logErr("registerOutParameter does not register the OUT parameter");
					throw new Fault("Call to registerOutParameter Method is Failed!");
				}
			}
			logMsg("registerOutParameter registers the OUT parameter");
		}
		catch(SQLException sqle)
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to registerOutParameter is Failed!");
		}
		catch ( Exception e )
		{
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to registerOutParameter is Failed!", e);
		}
		finally
		{
			try
			{
				if(cstmt != null)
				{
					cstmt.close();
					cstmt=null;
				}
				rsSch.dropTab("Longvarbinary_Tab",conn);
			}
			catch (Exception e) {}
		}
	}


	/* cleanup */
	public void  cleanup() throws Fault
	{
		try
		{
			// Close the database
			rsSch.dbUnConnect(conn);
			logMsg("Cleanup ok;");
		}
		catch (Exception e)
		{
			logErr("An error occurred while closing the database connection");
		}
	}
}
