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

/*
 * @(#)stmtClient2.java	1.12 02/01/12
 */

package com.sun.cts.tests.jdbc.ee.stmt.stmt2;

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 stmtClient2 class tests methods of Statement interface using 
 * Sun's J2EE Reference Implementation.
 * @author  
 * @version 1.7, 06/16/99
 */

public class stmtClient2 extends ServiceEETest implements Serializable
{
	private static final String testName = "jdbc.ee.stmt.stmt2";

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

	//Harness requirements 
	private transient Connection conn = null;
	private ResultSet rs=null;
	private Statement stmt=null;
	private Statement statemt=null;
	private transient DatabaseMetaData dbmd=null;
	private DataSource ds1 = null;
	private dbSchema dbSch=null;
	private rsSchema rsSch=null;
	private	String drManager=null;
	private Properties sqlp = null;
	private Properties props = null;
	private PreparedStatement pstmt = null;

	/* Run test in standalone mode */
	public static void main(String[] args) 
	{
		stmtClient2 theTests = new stmtClient2();
		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 = new Properties();
				String sqlStmt= p.getProperty("rsQuery","");
				InputStream istr= new FileInputStream(sqlStmt);
				sqlp.load(istr);*/
				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);
				}
				
				stmt=conn.createStatement();
				dbmd=conn.getMetaData();
				dbSch=new dbSchema();
				dbSch.createData(p,conn);
				rsSch=new rsSchema();
			}
			catch(SQLException ex)
			{
				logErr("SQL Exception : " + ex.getMessage());
			}
		} 
		catch ( Exception e ) 
		{
			logErr("Setup Failed!");
			TestUtil.printStackTrace(e);
		}
	}
	


	/*
	 * @testName:         testGetResultSet02
	 * @assertion:        The Statement object provides methods for executing SQL 
	 *                    statements and retrieving results.(See section 40.1 of 
	 *                    JDBC 2.0 API Reference & Tutorial second edition). 
	 *                    
	 *                    The driver must provide full support for Statement methods. 
	 *                    The driver must also support all the methods for executing 
	 *                    SQL Statements in a single batch (Batch Updates). (See 
	 *                    section 6.2.2.3 of Java2 Platform Enterprise Edition(J2EE)
	 *                    Specification v1.2)
	 *                    
	 *                    The getResultSet() method returns a ResultSet object; 
	 *                    the current result set as a ResultSet object; null if the
	 *                    result is an integer indicating that it is an update count 
	 *                    or there are no more results.(See JDK1.2.2 API documentation)
	 *                    
	 * @test_Strategy:    Get a Statement object and call execute() method for 
	 *                    updating a row.Then call getResultSet() method
	 *                    It should return a  Null ResultSet object
	 */
	public void testGetResultSet02() throws Fault
	{
		ResultSet retResSet=null;
		try
		{

			String sSqlStmt = sqlp.getProperty("Upd_Coffee_Tab","");
			logMsg("Query String :  " + sSqlStmt);

			logMsg("Calling getResultSet on Statement");
			stmt.execute(sSqlStmt);
			retResSet=stmt.getResultSet();

			if(retResSet==null)
			{
				logMsg("getResultSet method returns a Null ResultSet object " );
			}
			else
			{
				logErr(" getResultSet method does not return a ResultSet object");
				throw new Fault("Call to getResultSet is Failed!");
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getResultSet is Failed!", sqle);
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Fault("Call to getResultSet is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetResultSetConcurrency01
	 * @assertion:        The Statement object provides methods for executing SQL 
	 *                    statements and retrieving results.(See section 40.1 of 
	 *                    JDBC 2.0 API Reference & Tutorial second edition). 
	 *                    
	 *                    The driver must provide full support for Statement methods. 
	 *                    The driver must also support all the methods for executing 
	 *                    SQL Statements in a single batch (Batch Updates). (See 
	 *                    section 6.2.2.3 of Java2 Platform Enterprise Edition(J2EE)
	 *                    Specification v1.2)
	 *                    
	 *                    The getResultSetConcurrency() method returns an integer value; 
	 *                    the value representing the concurrency mode for the ResultSet
	 *                    objects and the value can be any one of the following
	 *                    ResultSet.CONCUR_READ_ONLY and ResultSet.CONCUR_UPDATABLE.
	 *                    (See JDK1.2.2 API documentation)
	 *                    
	 * @test_Strategy:    Get a Statement object and call getResultSetConcurrency() method
	 *                    It should return an int value either CONCUR_READ_ONLY or
	 *                    CONCUR_UPDATABLE.
	 */
	public void testGetResultSetConcurrency01() throws Fault
	{
		int rsConcur =0;
		try
		{
			rsConcur=stmt.getResultSetConcurrency();

			if ((rsConcur==ResultSet.CONCUR_READ_ONLY) || (rsConcur==ResultSet.CONCUR_UPDATABLE))
			{
				logMsg("getResultSetConcurrency method returns ResultSet Concurrency mode  "+ rsConcur);
			}
			else
			{
				logErr(" getResultSetConcurrency method does not return a valid value");
				throw new Fault("Call to getResultSetConcurrency is Failed!");
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getResultSetConcurrency is Failed!", sqle);
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Fault("Call to getResultSetConcurrency is Failed!", e);
		}
	}



	/*
	 * @testName:         testGetResultSetType01
	 * @assertion:        The Statement object provides methods for executing SQL 
	 *                    statements and retrieving results.(See section 40.1 of 
	 *                    JDBC 2.0 API Reference & Tutorial second edition). 
	 *                    
	 *                    The driver must provide full support for Statement methods.
	 *                    The driver must also support all the methods for executing 
	 *                    SQL Statements in a single batch (Batch Updates). (See 
	 *                    section 6.2.2.3 of Java2 Platform Enterprise Edition(J2EE)
	 *                    Specification v1.2)
	 *                    
	 *                    The getResultSetType() method returns an integer value; 
	 *                    the value representing the type of the ResultSet objects
	 *                    and the value can be any one of the following
	 *                    ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_SENSITIVE
	 *                    and ResultSet.TYPE_SCROLL_INSENSITIVE.
	 *                    (See JDK1.2.2 API documentation)
	 *                    
	 * @test_Strategy:    Get a Statement object and call getResultSetType() method
	 *                    It should return an int value which should be either
	 *                    TYPE_FORWARD_ONLY or TYPE_SCROLL_INSENSITIVE or TYPE_SCROLL_SENSITIVE
	 */
	public void testGetResultSetType01() throws Fault
	{
		int rsType =0;
		try
		{
			rsType=stmt.getResultSetType();
			
			if (rsType==ResultSet.TYPE_FORWARD_ONLY) 
			{
				logMsg("getResultSetType method returns TYPE_FORWARD_ONLY"+ rsType);
			}
			else if (rsType==ResultSet.TYPE_SCROLL_INSENSITIVE) 
			{
				logMsg("getResultSetType method returns TYPE_SCROLL_INSENSITIVE "+ rsType);
			}
			else if (rsType==ResultSet.TYPE_SCROLL_SENSITIVE) 
			{
				logMsg("getResultSetType method returns TYPE_SCROLL_SENSITIVE  "+ rsType);
			}
			else
			{
				logErr(" getResultSetType method does not return a valid value");
				throw new Fault("Call to getResultSetType is Failed!");
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getResultSetType is Failed!", sqle);
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Fault("Call to getResultSetType is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetResultSetType02
	 * @assertion:        The Statement object provides methods for executing SQL 
	 *                    statements and retrieving results.(See section 40.1 of 
	 *                    JDBC 2.0 API Reference & Tutorial second edition).
	 *                    
	 *                    The driver must provide full support for Statement methods. 
	 *                    The driver must also support all the methods for executing 
	 *                    SQL Statements in a single batch (Batch Updates). (See 
	 *                    section 6.2.2.3 of Java2 Platform Enterprise Edition(J2EE)
	 *                    Specification v1.2)
	 *                    
	 *                    The getResultSetType() method returns an integer value; 
	 *                    the value representing the type of the ResultSet objects
	 *                    and the value can be any one of the following
	 *                    ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_SENSITIVE
	 *                    and ResultSet.TYPE_SCROLL_INSENSITIVE.
	 *                    (See JDK1.2.2 API documentation)
	 *                    
	 * @test_Strategy:    Call Connection.createStatement with the Type mode as
	 *                    TYPE_FORWARD_ONLY and call getResultSetType() method
	 *                    It should return a int value and the value should be equal 
	 *                    to ResultSet.TYPE_FORWARD_ONLY
	 */
	public void testGetResultSetType02() throws Fault
	{
		int rsType =0;
		Statement statemt=null;
		try
		{
			logMsg("Creating Statement object with the ResultSet Type and Type");
			statemt= conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY);

			//invoking the getResultSetType method
			rsType=statemt.getResultSetType();

			if (rsType==ResultSet.TYPE_FORWARD_ONLY) 
			{
				logMsg("getResultSetType method returns TYPE_FORWARD_ONLY "+ rsType);
			}
			else
			{
				statemt.close();
				logErr(" getResultSetType method does not return a valid value");
				throw new Fault("Call to getResultSetType is Failed!");
			}
			statemt.close();
		}
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getResultSetType is Failed!", sqle);
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Fault("Call to getResultSetType is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetResultSetType03
	 * @assertion:        The Statement object provides methods for executing SQL 
	 *                    statements and retrieving results.(See section 40.1 of 
	 *                    JDBC 2.0 API Reference & Tutorial second edition). 
	 *                    
	 *                    The driver must provide full support for Statement methods. 
	 *                    The driver must also support all the methods for executing 
	 *                    SQL Statements in a single batch (Batch Updates). (See 
	 *                    section 6.2.2.3 of Java2 Platform Enterprise Edition(J2EE)
	 *                    Specification v1.2)
	 *                    
	 *                    The getResultSetType() method returns an integer value; 
	 *                    the value representing the type of the ResultSet objects
	 *                    and the value can be any one of the following
	 *                    ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_SENSITIVE
	 *                    and ResultSet.TYPE_SCROLL_INSENSITIVE.
	 *                    (See JDK1.2.2 API documentation)
	 *                    
	 * @test_Strategy:    Call Connection.createStatement with the Type mode as
	 *                    TYPE_SCROLL_INSENSITIVE and call getResultSetType() method
	 *                    It should return a int value and the value should be equal 
	 *                    to ResultSet.TYPE_SCROLL_INSENSITIVE
	 */
	public void testGetResultSetType03() throws Fault
	{
		int rsType =0;
		Statement statemt=null;
		try
		{
			logMsg("Creating Statement object with the ResultSet Type and Type");
			statemt= conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);

			//invoking the getResultSetType method
			rsType=statemt.getResultSetType();

			if (rsType==ResultSet.TYPE_SCROLL_INSENSITIVE) 
			{
				logMsg("getResultSetType method returns TYPE_SCROLL_INSENSITIVE "+ rsType);
			}
			else
			{
				statemt.close();
				logErr(" getResultSetType method does not return a valid value");
				throw new Fault("Call to getResultSetType is Failed!");
			}
			statemt.close();
		}
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getResultSetType is Failed!", sqle);
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Fault("Call to getResultSetType is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetUpdateCount01
	 *                    
	 * @assertion:        A driver must provide support for Statement and 
	 *                    ResultSet.  This implies that the methods in the
	 *                    Statement interface must be implemented and must behave as
	 *                    specified in the JDBC 1.0 and 2.0 specifications.	(See 
	 *                    Section :40.3 Statement Methods JDBC 2.0 API Tutorial 
	 *                    & Reference). 
	 *                    
	 *                    The driver must provide full support for Statement methods. 
	 *                    The driver must also support all the methods for executing 
	 *                    SQL Statements in a single batch (Batch Updates). (See 
	 *                    section 6.2.2.3 of Java2 Platform Enterprise Edition(J2EE)
	 *                    Specification v1.2)
	 *                    
	 *                    The getUpdateCount() method should return a integer value;
	 *                    the value might be greater than 0 representing the rows affected; 
	 *                    0 if no rows are affected or if DDL statement; -1 if the result
	 *                    is a ResultSet object or there are no more results
	 *                    (See JDK 1.2.2 API Documentation)
	 *                    
	 * @test_Strategy:    Get a Statement object and call the execute() method for 
	 *                    updating a row and call getUpdateCount() method
	 *                    It should return a int value and the value should be 
	 *                    equal to number of rows with the specified condition for update
	 */
	public void testGetUpdateCount01() throws Fault
	{
		int updCountVal=0;
		int rowsAffectVal=0;
		try
		{
			String sSqlStmt = sqlp.getProperty("Upd_Coffee_Tab","");
			logMsg("Query String : " + sSqlStmt);
			stmt.execute(sSqlStmt);

			// invoke on the getUpdateCount
			logMsg("Calling getUpdateCount on Statement");
			updCountVal = stmt.getUpdateCount();

			String sQuery = sqlp.getProperty("Coffee_Updcount_Query","");
			logMsg("Query String : " + sQuery);
			ResultSet rs1=stmt.executeQuery(sQuery);
			rs1.next();

			rowsAffectVal=rs1.getInt(1);
			logMsg("Number of Rows Affected by Update Statement " + rowsAffectVal);

			if(updCountVal==rowsAffectVal)
			{
				logMsg("getUpdateCount method returns :" + updCountVal );
			}
			else
			{
				logErr(" getUpdateCount method returns a invalid value" );
				throw new Fault("Call to getUpdateCount is Failed!");
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getUpdateCount is Failed!", sqle);
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Fault("Call to getUpdateCount is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetUpdateCount02
	 *                    
	 * @assertion:        A driver must provide support for Statement and 
	 *                    ResultSet.  This implies that the methods in the
	 *                    Statement interface must be implemented and must behave as
	 *                    specified in the JDBC 1.0 and 2.0 specifications.	(See 
	 *                    Section :40.3 Statement Methods JDBC 2.0 API Tutorial 
	 *                    & Reference). 
	 *                    
	 *                    The driver must provide full support for Statement methods. 
	 *                    The driver must also support all the methods for executing 
	 *                    SQL Statements in a single batch (Batch Updates). (See 
	 *                    section 6.2.2.3 of Java2 Platform Enterprise Edition(J2EE)
	 *                    Specification v1.2)
	 *                    
	 *                    The getUpdateCount() method should return a integer value;
	 *                    the value might be greater than 0 representing the rows affected; 
	 *                    0 if no rows are affected or if DDL statement; -1 if the result
	 *                    is a ResultSet object or there are no more results
	 *                    (See JDK 1.2.2 API Documentation)
	 *                    
	 * @test_Strategy:    Get a Statement object and call the execute() method for 
	 *                    selecting a non-existent row and call getUpdateCount() method
	 *                    It should return a int value and the value should be 
	 *                    equal to -1
	 */
	public void testGetUpdateCount02() throws Fault
	{
		int updCountVal=0;
		try
		{
			String sSqlStmt = sqlp.getProperty("SelCoffeeNull","");
			logMsg("Query String : " + sSqlStmt);
			stmt.execute(sSqlStmt);
			
			// invoke on the getUpdateCount
			logMsg("Calling getMoreResults on Statement");
			updCountVal = stmt.getUpdateCount();

			if(updCountVal== -1)
			{
				logMsg("getUpdateCount method returns :" + updCountVal );
			}
			else
			{
				logErr(" getUpdateCount method returns a invalid value" );
				throw new Fault("Call to getUpdateCount is Failed!");
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getUpdateCount is Failed!", sqle);
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Fault("Call to getUpdateCount is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetWarnings
	 *                    
	 * @assertion:        A driver must provide support for Statement and 
	 *                    ResultSet.  This implies that the methods in the
	 *                    Statement interface must be implemented and must behave as
	 *                    specified in the JDBC 1.0 and 2.0 specifications.	(See 
	 *                    Section :40.3 Statement Methods JDBC 2.0 API Tutorial 
	 *                    & Reference). 
	 *                    
	 *                    The driver must provide full support for Statement methods. 
	 *                    The driver must also support all the methods for executing 
	 *                    SQL Statements in a single batch (Batch Updates). (See 
	 *                    section 6.2.2.3 of Java2 Platform Enterprise Edition(J2EE)
	 *                    Specification v1.2)
	 *                    
	 *                    The getWarnings() method should return a SQLWarning object;
	 *                    or null if there are no warnings (See JDK 1.2.2 API
	 *                    Documentation)
	 *                    
	 * @test_Strategy:    Get a Statement object and call getWarnings() method
	 *                    should return an SQLWarning object
	 */
	public void testGetWarnings() throws Fault
	{
		try
		{
			
			rsSch.createTab("Integer_Tab",sqlp,conn);

			// get the CallableStatement object 
			CallableStatement cstmt = conn.prepareCall("{call Integer_Proc(?,?,?)}");
			logMsg("The Callable Statement " + cstmt);

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

			//execute the procedure
			cstmt.execute();

			//invoke getInt method
			int nRetVal = cstmt.getInt(1);
			Statement state = (Statement) cstmt;

			logMsg("Calling getWarnings method");
			SQLWarning sWarning = state.getWarnings();

			if(sWarning instanceof SQLWarning)
			{
				logMsg("getWarnings method returns a SQLWarning object");
			}
			else if(sWarning == null)
			{
				logErr("getWarnings() method returns a null SQLWarning Object");
			}
			rsSch.dropTab("Integer_Tab",conn);
			
		}
		catch(SQLException sqle)
		{
			logErr("SQLException "+ sqle.getMessage());
			throw new Fault("Call to getWarnings is Failed!");
		}
		catch(Exception ex)
		{
			logErr("Unexpected Exception" + ex.getMessage());
			throw new Fault("Call to getWarnings is Failed!");
		}
	}



	/*
	 * @testName:         testSetFetchDirection04
	 * @assertion:        A driver must provide support for Statement and 
	 *                    ResultSet.  This implies that the methods in the
	 *                    Statement interface must be implemented and must behave as
	 *                    specified in the JDBC 1.0 and 2.0 specifications.	(See 
	 *                    Section :40.3 Statement Methods JDBC 2.0 API Tutorial 
	 *                    & Reference). 
	 *                    
	 *                    The driver must provide full support for Statement methods. 
	 *                    The driver must also support all the methods for executing 
	 *                    SQL Statements in a single batch (Batch Updates). (See 
	 *                    section 6.2.2.3 of Java2 Platform Enterprise Edition(J2EE)
	 *                    Specification v1.2)
	 *                    
	 *                    The setFetchDirection(int dir) method sets the statement
	 *                    object's fetch direction.  The setFetchDirection method does
	 *                    not return any value. (See JDK 1.2.2 API Documentation)
	 *                    
	 * @test_Strategy:    Get a Statement object and call the setFetchDirection(int direction)
	 *                    method with an invalid value and it should throw an SQLException
	 */
	public void testSetFetchDirection04() throws Fault
	{
		boolean sqlExceptFlag =false;
		try
		{

			logMsg("Calling setFetchDirection method ");
			try
			{
				stmt.setFetchDirection(-1);
			}
			catch (SQLException sqe)
			{
				sqlExceptFlag = true;
			}

			if(sqlExceptFlag)
			{
				logMsg("setFetchDirection method does not sets the invalid direction for the ResultSet " );
			}
			else
			{
				logErr("setFetchDirection method sets the invalid direction for ResultSet" );
				throw new Fault("Call to setFetchDirection is Failed");
			}
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Fault("Call to setFetchDirection is Failed!", e);
		}
	}



	/*
	 * @testName:         testSetFetchSize02
	 * @assertion:        A driver must provide support for Statement and 
	 *                    ResultSet.  This implies that the methods in the
	 *                    Statement interface must be implemented and must behave as
	 *                    specified in the JDBC 1.0 and 2.0 specifications.	(See 
	 *                    Section :40.3 Statement Methods JDBC 2.0 API Tutorial 
	 *                    & Reference). 
	 *                    
	 *                    The driver must provide full support for Statement methods. 
	 *                    The driver must also support all the methods for executing 
	 *                    SQL Statements in a single batch (Batch Updates). (See 
	 *                    section 6.2.2.3 of Java2 Platform Enterprise Edition(J2EE)
	 *                    Specification v1.2)
	 *                    
	 *                    The setFetchSize(int rowsize) method sets the number of rows
	 *                    to fetch from the database specified by the value of rowsize.
	 *                    The setFetchSize does not return any value. (See JDK 1.2.2 
	 *                    API Documentation)
	 *                    
	 * @test_Strategy:    Get a Statement object and call the setFetchSize(int rows)
	 *                    method with the value of Statement.getMaxRows and call 
	 *                    getFetchSize() method and it should return a int value
	 *                    that is been set
	 */
	public void testSetFetchSize02() throws Fault
	{
		int maxFetchSizeVal=50;
		int maxRowsVal=0;
		int retVal=0;
		
		try
		{
			//invoking the getMaxRows method
			stmt.setMaxRows(maxFetchSizeVal);
			maxRowsVal=stmt.getMaxRows();
			logMsg("Maximum Rows that Statement can contain " + maxRowsVal);

			logMsg("Calling the setFetchSize method");
			stmt.setFetchSize(maxRowsVal);

			// invoke on the getFetchSize
			retVal = stmt.getFetchSize();

			if(maxFetchSizeVal == retVal)
			{
				logMsg("setFetchSize method sets the value as FetchSize for ResultSet" );
			}
			else
			{
				logErr("setFetchSize method does not set the value as Fetch Size for ResultSet" );
				throw new Fault("Call to setFetchSize is Failed");
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to setFetchSize is Failed!", sqle);
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Fault("Call to setFetchSize is Failed!", e);
		}
	}


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


}
