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

/*
 * @(#)resultSetClient13.java	1.13 02/01/12
 */

package com.sun.cts.tests.jdbc.ee.resultSet.resultSet13;

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 resultSetClient13 class tests methods of  resultSet interface using 
 * Sun's J2EE Reference Implementation.
 * @author  
 * @version 1.7, 99/10/12
 */

public class resultSetClient13 extends ServiceEETest implements Serializable
{
	private static final String testName = "jdbc.ee.resultSet.resultSet13";

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

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

	/* Run test in standalone mode */
	public static void main(String[] args) 
	{
		resultSetClient13 theTests = new resultSetClient13();
		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
			{
				props=p;
				drManager = p.getProperty("DriverManager","");
				if (drManager.length() == 0)
					throw new Fault("Invalid DriverManager Name");
				/*sqlp=new Properties();
				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);
				}
				dbSch = new dbSchema();
				rsSch= new rsSchema();
				stmt = conn.createStatement(/*ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY*/);
				dbmd =  conn.getMetaData();
			}
			catch(SQLException ex)
			{
				logErr("SQL Exception : " + ex.getMessage());
			}
		} 
		catch ( Exception e ) 
		{
			logErr("Setup Failed!");
			TestUtil.printStackTrace(e);
		}
	}



	
	/* @testName:       testGetByte61
	 *                    
	 * @assertion:      The ResultSet object contains the results of executing an 
	 *                  SQL Query.  ResultSets may hava different levels of functionality 
	 *                  (ResultSet Types TYPE_FORWARD_ONLY, TYPE_SCROLL_SENSITIVE, 
	 *                  TYPE_SCROLL_INSENSITIVE) and update capabilities (ResultSet 
	 *                  Concurrency). (See section 26.1 of JDBC 2.0 API Reference 
	 *                  & Tutorial second edition).  The JDBC driver must provide full 
	 *                  support for TYPE_SCROLL_INSENSITIVE result sets. (See section 
	 *                  6.2.2.3 of Java2 Platform Enterprise Edition Specification v1.2)
	 *                  The getByte(String columnName) gets the value of the designated column in 
	 *                  the current row of this ResultSet object as a byte in the Java programming
	 *                  language; if the value is SQL NULL, the value returned is 0.
	 *
	 * @test_Strategy:  Get a PreparedStatement object from the connection to the database.
	 *                  Using this,update the maximum value of table Decimal_Tab with the maximum
	 *                  value of table Tinyint_Tab.Now execute a query to get the maximum value of
	 *                  Decimal_Tab table and retrieve the result of the query using the 
	 *                  getByte(String columnName) method.Compare the returned value, with the 
	 *                  maximum value of table Tinyint_Tab extracted from the ctssql.stmt file.
	 *                  Both of them should be equal.   
	 */
	public void testGetByte61() throws Fault
	{
		byte retValue;
		byte maxByteVal;
		String str =null;
		BigDecimal bigDecimalVal=null;
		ResultSet rs = null;
		ResultSetMetaData rsmd=null;
		String columname=null;
		try
		{
			rsSch.createTab("Decimal_Tab",sqlp,conn);
			//to get the query string
			String Max_Val_Query=sqlp.getProperty("Decimal_Query_Max","");
			str=rsSch.extractVal("Tinyint_Tab",1,sqlp,conn); 
			String sPrepStatement=sqlp.getProperty("Decimal_Tab_Max_Update",null);
			bigDecimalVal= new BigDecimal(str);
			pstmt = conn.prepareStatement(sPrepStatement);
			pstmt.setBigDecimal(1,bigDecimalVal);
			pstmt.executeUpdate();
			rs=stmt.executeQuery(Max_Val_Query);
			rsmd=rs.getMetaData();
			rs.next();
			logMsg("Calling getByte on Decimal_Tab");
			columname=rsmd.getColumnName(1);
			retValue=rs.getByte(columname);
			maxByteVal =Byte.parseByte(str);
			
			if(maxByteVal == retValue)
			{
				logMsg("getByte method returns : "+ retValue);
			}
			else
			{
				logErr("getByte method does not return the Maximum Value from Decimal Table ");
				throw new Fault("Call to getByte is Failed!");
			}
		}
			
		catch(SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage() );
			throw new Fault("Call to getByte is Failed!", sqle);
		}
		catch(Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Fault("Call to getByte is Failed!", e);
		}
		finally
		{
			try {
			pstmt.close();
			rs.close();
			rsSch.dropTab("Decimal_Tab",conn);
			}catch (Exception e) {};
		}

		
	}



	/* @testName:         testGetByte62
	 *                    
	 * @assertion:        The ResultSet object contains the results of executing an 
	 *                    SQL Query.  ResultSets may hava different levels of functionality 
	 *                    (ResultSet Types TYPE_FORWARD_ONLY, TYPE_SCROLL_SENSITIVE, 
	 *                    TYPE_SCROLL_INSENSITIVE) and update capabilities (ResultSet 
	 *                    Concurrency). (See section 26.1 of JDBC 2.0 API Reference 
	 *                    & Tutorial second edition).  The JDBC driver must provide full 
	 *                    support for TYPE_SCROLL_INSENSITIVE result sets. (See section 
	 *                    6.2.2.3 of Java2 Platform Enterprise Edition Specification v1.2)
	 *                    The getByte(String columnName) gets the value of the designated column in 
	 *                    the current row of this ResultSet object as a byte in the Java programming
	 *                    language; if the value is SQL NULL, the value returned is 0.
	 *
	 * @test_Strategy:  Get a PreparedStatement object from the connection to the database.
	 *                  Using this,update the minimum value of table Decimal_Tab with the minimum
	 *                  value of table Tinyint_Tab.Now execute a query to get the minimum value of
	 *                  Decimal_Tab table and retrieve the result of the query using the 
	 *                  getByte(String columnName) method.Compare the returned value, with the 
	 *                  minimum value of table Tinyint_Tab extracted from the ctssql.stmt file.
	 *                  Both of them should be equal.   
	 */
	public void testGetByte62() throws Fault
	{
		byte retValue;
		byte minByteVal;
		String str =null;
		BigDecimal bigDecimalVal=null;
		ResultSet rs = null;
		ResultSetMetaData rsmd=null;
		String columname=null;
		try
		{
			rsSch.createTab("Decimal_Tab",sqlp,conn);
			//to get the query string
			String Min_Val_Query=sqlp.getProperty("Decimal_Query_Min","");
			str=rsSch.extractVal("Tinyint_Tab",2,sqlp,conn); 
			String sPrepStatement=sqlp.getProperty("Decimal_Tab_Min_Update",null);
			bigDecimalVal= new BigDecimal(str);
			pstmt = conn.prepareStatement(sPrepStatement);
			pstmt.setBigDecimal(1,bigDecimalVal);
			pstmt.executeUpdate();
			rs=stmt.executeQuery(Min_Val_Query);
			rsmd=rs.getMetaData();
			rs.next();
			logMsg("Calling getByte on Decimal_Tab");
			columname=rsmd.getColumnName(1);
			retValue=rs.getByte(columname);
			minByteVal =Byte.parseByte(str);
			
			if(minByteVal == retValue)
			{
				logMsg("getByte method returns : "+ retValue);
			}
			else
			{
				logErr("getByte method does not return the Minimum value from Decimal Table ");
				throw new Fault("Call to getByte is Failed!");
			}
		}
		 
		catch(SQLException sqle)
		{
			logErr("SQL Exception " + sqle.getMessage() );
			throw new Fault("Call to getByte is Failed!", sqle);
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Fault("Call to getByte is Failed!", e);
		}
		finally
		{
			try
			{
				pstmt.close();
				rs.close();
				rsSch.dropTab("Decimal_Tab",conn);
			} catch (Exception e) {};
		}
	}


	/* @testName:       testGetByte63
	 *                    
	 * @assertion:      The ResultSet object contains the results of executing an 
	 *                  SQL Query.  ResultSets may hava different levels of functionality 
	 *                  (ResultSet Types TYPE_FORWARD_ONLY, TYPE_SCROLL_SENSITIVE, 
	 *                  TYPE_SCROLL_INSENSITIVE) and update capabilities (ResultSet 
	 *                  Concurrency). (See section 26.1 of JDBC 2.0 API Reference 
	 *                  & Tutorial second edition).  The JDBC driver must provide full 
	 *                  support for TYPE_SCROLL_INSENSITIVE result sets. (See section 
	 *                  6.2.2.3 of Java2 Platform Enterprise Edition Specification v1.2)
	 *                  The getByte(String columnName) gets the value of the designated column in 
	 *                  the current row of this ResultSet object as a byte in the Java programming
	 *                  language; if the value is SQL NULL, the value returned is 0.
	 *
	 * @test_Strategy:  Get a ResultSet object by executing the query that returns null value
	 *                  from table Double_Tab.Call the getByte(String columnName) method.Check if the value 
	 *                  returned is zero.
	 */
	public void testGetByte63() throws Fault
	{
		byte retValue;
		String snullByteVal =null;
		ResultSet rs = null;
		ResultSetMetaData rsmd=null;
		String columname=null;
		try
		{
			rsSch.createTab("Decimal_Tab",sqlp,conn);
			//to get the query string
			String Null_Val_Query=sqlp.getProperty("Decimal_Query_Null","");
			rs=stmt.executeQuery(Null_Val_Query);
			rsmd=rs.getMetaData();
			rs.next();
			logMsg("Calling getByte on Decimal_Tab");
			columname=rsmd.getColumnName(1);
			retValue=rs.getByte(columname);
			
			if(retValue == 0)
			{
				logMsg("Calling getByte method on a SQL Null column returns"+retValue);
			}
			else
			{
				logErr("getByte method does not return the value zero ");
				throw new Fault("Call to getByte is Failed!");
			}
			
		}
		catch(SQLException sqle)
		{
			logErr("SQL Exception " + sqle.getMessage() );
			throw new Fault("Call to getByte is Failed!", sqle);
		}
		catch(Exception e)
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Fault("Call to getByte is Failed!", e);
		}
		finally
		{
			try {
			rs.close();
			rsSch.dropTab("Decimal_Tab",conn);
			}catch (Exception e) {};
		}
	}


	
	/* @testName:       testGetByte64
	 *                    
	 * @assertion:      The ResultSet object contains the results of executing an 
	 *                  SQL Query.  ResultSets may hava different levels of functionality 
	 *                  (ResultSet Types TYPE_FORWARD_ONLY, TYPE_SCROLL_SENSITIVE, 
	 *                  TYPE_SCROLL_INSENSITIVE) and update capabilities (ResultSet 
	 *                  Concurrency). (See section 26.1 of JDBC 2.0 API Reference 
	 *                  & Tutorial second edition).  The JDBC driver must provide full 
	 *                  support for TYPE_SCROLL_INSENSITIVE result sets. (See section 
	 *                  6.2.2.3 of Java2 Platform Enterprise Edition Specification v1.2)
	 *                  The getByte(String columnName) gets the value of the designated column in 
	 *                  the current row of this ResultSet object as a byte in the Java programming
	 *                  language; if the value is SQL NULL, the value returned is 0.
	 *
	 * @test_Strategy:  Get a PreparedStatement object from the connection to the database.
	 *                  Using this,update the maximum value of table Numeric_Tab with the maximum
	 *                  value of table Tinyint_Tab.Now execute a query to get the maximum value of
	 *                  Numeric_Tab table and retrieve the result of the query using the 
	 *                  getByte(String columnName) method.Compare the returned value, with the 
	 *                  maximum value of table Tinyint_Tab extracted from the ctssql.stmt file.
	 *                  Both of them should be equal.   
	 */
	public void testGetByte64() throws Fault
	{	
		byte retValue;
		byte maxByteVal;
		String str =null;
		BigDecimal bigDecimalVal=null;
		ResultSet rs = null;
		ResultSetMetaData rsmd=null;
		String columname=null;
		try
		{
			rsSch.createTab("Numeric_Tab",sqlp,conn);
			//to get the query string
			String Max_Val_Query=sqlp.getProperty("Numeric_Query_Max","");
			str=rsSch.extractVal("Tinyint_Tab",1,sqlp,conn); 
			String sPrepStatement=sqlp.getProperty("Numeric_Tab_Max_Update",null);
			bigDecimalVal= new BigDecimal(str);
			pstmt = conn.prepareStatement(sPrepStatement);
			pstmt.setBigDecimal(1,bigDecimalVal);
			pstmt.executeUpdate();
			rs=stmt.executeQuery(Max_Val_Query);
			rsmd=rs.getMetaData();
			rs.next();
			logMsg("Calling getByte on Numeric_Tab");
			columname=rsmd.getColumnName(1);
			retValue=rs.getByte(columname);
			maxByteVal =Byte.parseByte(str);
				
			if(maxByteVal == retValue)
			{
				logMsg("getByte method returns : "+ retValue);
			}
			else
			{
				logErr("getByte method does not return the Maximum value from Numeric Table ");
				throw new Fault("Call to getByte is Failed!");
			}
		}
		 
		catch(SQLException sqle)
		{
			logErr("SQL Exception " + sqle.getMessage() );
			throw new Fault("Call to getByte is Failed!", sqle);
		}		
		catch(Exception e)
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Fault("Call to getByte is Failed!", e);
		}
		finally
		{
			try
			{
				pstmt.close();
				rs.close();
				rsSch.dropTab("Numeric_Tab",conn);
			}
			catch (Exception e) {};
		}

		
	}


	
	/* @testName:       testGetByte65
	 *                    
	 * @assertion:      The ResultSet object contains the results of executing an 
	 *                  SQL Query.  ResultSets may hava different levels of functionality 
	 *                  (ResultSet Types TYPE_FORWARD_ONLY, TYPE_SCROLL_SENSITIVE, 
	 *                  TYPE_SCROLL_INSENSITIVE) and update capabilities (ResultSet 
	 *                  Concurrency). (See section 26.1 of JDBC 2.0 API Reference 
	 *                  & Tutorial second edition).  The JDBC driver must provide full 
	 *                  support for TYPE_SCROLL_INSENSITIVE result sets. (See section 
	 *                  6.2.2.3 of Java2 Platform Enterprise Edition Specification v1.2)
	 *                  The getByte(String columnName) gets the value of the designated column in 
	 *                  the current row of this ResultSet object as a byte in the Java programming
	 *                  language; if the value is SQL NULL, the value returned is 0.
	 *
	 * @test_Strategy:  Get a PreparedStatement object from the connection to the database.
	 *                  Using this,update the minimum value of table Numeric_Tab with the minimum
	 *                  value of table Tinyint_Tab.Now execute a query to get the minimum value of
	 *                  Numeric_Tab table and retrieve the result of the query using the 
	 *                  getByte(String columnName) method.Compare the returned value, with the 
	 *                  minimum value of table Tinyint_Tab extracted from the ctssql.stmt file.
	 *                  Both of them should be equal.
	 */
	public void testGetByte65() throws Fault
	{
		byte retValue;
		byte minByteVal;
		String str =null;
		BigDecimal bigDecimalVal=null;
		ResultSet rs = null;
		ResultSetMetaData rsmd=null;
		String columname=null;
		try
		{
			rsSch.createTab("Numeric_Tab",sqlp,conn);
			//to get the query string
			String Min_Val_Query=sqlp.getProperty("Numeric_Query_Min","");
			str=rsSch.extractVal("Tinyint_Tab",2,sqlp,conn); 
			String sPrepStatement=sqlp.getProperty("Numeric_Tab_Min_Update",null);
			bigDecimalVal= new BigDecimal(str);
			pstmt = conn.prepareStatement(sPrepStatement);
			pstmt.setBigDecimal(1,bigDecimalVal);
			pstmt.executeUpdate();
			rs=stmt.executeQuery(Min_Val_Query);
			rsmd=rs.getMetaData();
			rs.next();
			logMsg("Calling getByte on Numeric_Tab");
			columname=rsmd.getColumnName(1);
			retValue=rs.getByte(columname);
			minByteVal =Byte.parseByte(str);
			
			if(minByteVal == retValue)
			{
				logMsg("getByte method returns : "+ retValue);
			}
			else
			{
				logErr("getByte method does not return the Minimum value from Numeric Table ");
				throw new Fault("Call to getByte is Failed!");
			}
		}
				
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage() );
			throw new Fault("Call to getByte is Failed!", sqle);
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Fault("Call to getByte is Failed!", e);
		}
		finally
		{
			try
			{
				pstmt.close();
				rs.close();
				rsSch.dropTab("Numeric_Tab",conn);
			}catch (Exception e) {};
		}
	}



	/* @testName:       testGetByte66
	 *                    
	 * @assertion:      The ResultSet object contains the results of executing an 
	 *                  SQL Query.  ResultSets may hava different levels of functionality 
	 *                  (ResultSet Types TYPE_FORWARD_ONLY, TYPE_SCROLL_SENSITIVE, 
	 *                  TYPE_SCROLL_INSENSITIVE) and update capabilities (ResultSet 
	 *                  Concurrency). (See section 26.1 of JDBC 2.0 API Reference 
	 *                  & Tutorial second edition).  The JDBC driver must provide full 
	 *                  support for TYPE_SCROLL_INSENSITIVE result sets. (See section 
	 *                  6.2.2.3 of Java2 Platform Enterprise Edition Specification v1.2)
	 *                  The getByte(String columnName) gets the value of the designated column in 
	 *                  the current row of this ResultSet object as a byte in the Java programming
	 *                  language; if the value is SQL NULL, the value returned is 0.
	 *
	 * @test_Strategy:  Get a ResultSet object by executing the query that returns null value
	 *                  from table Numeric_Tab.Call the getByte(String columnName) method.Check if the value 
	 *                  returned is zero.
     */	
    public void testGetByte66() throws Fault
	{
		byte retValue;
		String snullByteVal =null;
		ResultSet rs = null;
		ResultSetMetaData rsmd=null;
		String columname=null;
		try
		{
			rsSch.createTab("Numeric_Tab",sqlp,conn);
			//to get the query string
			String Null_Val_Query=sqlp.getProperty("Numeric_Query_Null","");
			rs=stmt.executeQuery(Null_Val_Query);
			rsmd=rs.getMetaData();
			rs.next();
			logMsg("Calling  getByte on Numeric_Tab");
			columname=rsmd.getColumnName(1);
			retValue=rs.getByte(columname);
			
			if(retValue == 0)
			{
				logMsg("Calling getByte method on a SQL Null column returns"+retValue);
			}
			else
			{
				logErr("getByte method does not return the value zero ");
				throw new Fault("Call to getByte is Failed!");
			}
			
		}
		catch (SQLException sqle)
		{
			logErr("SQL Exception " + sqle.getMessage() );
			throw new Fault("Call to getByte is Failed!", sqle);
		}
		catch (Exception e)
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Fault("Call to getByte is Failed!", e);
		}
		finally
		{
			try
			{
				rs.close();
				rsSch.dropTab("Numeric_Tab",conn);
			}catch (Exception e) {};
		}
	}





	/* @testName:       testGetByte70
	 *                    
	 * @assertion:      The ResultSet object contains the results of executing an 
	 *                  SQL Query.  ResultSets may hava different levels of functionality 
	 *                  (ResultSet Types TYPE_FORWARD_ONLY, TYPE_SCROLL_SENSITIVE, 
	 *                  TYPE_SCROLL_INSENSITIVE) and update capabilities (ResultSet 
	 *                  Concurrency). (See section 26.1 of JDBC 2.0 API Reference 
	 *                  & Tutorial second edition).  The JDBC driver must provide full 
	 *                  support for TYPE_SCROLL_INSENSITIVE result sets. (See section 
	 *                  6.2.2.3 of Java2 Platform Enterprise Edition Specification v1.2)
	 *                  The getByte(String columnName) gets the value of the designated column in 
	 *                  the current row of this ResultSet object as a byte in the Java programming
	 *                  language; if the value is SQL NULL, the value returned is 0.
	 *
	 * @test_Strategy:  Get a PreparedStatement object from the connection to the database.
	 *                  Using this,update the table Char_Tab with the maximum value of 
	 *                  table Tinyint_Tab.Now execute a query to get that value from
	 *                  Char_Tab table and retrieve the result of the query using the 
	 *                  getByte(String columnName) method.Compare the returned value, with the 
	 *                  maximum value of table Tinyint_Tab extracted from the ctssql.stmt file.
	 *                  Both of them should be equal.
	 */
	public void testGetByte70() throws Fault
	{
		byte retValue;
		byte maxByteVal;
		String str =null;
		ResultSet rs = null;
		ResultSetMetaData rsmd=null;
		String columname=null;
		try
		{
			rsSch.createTab("Char_Tab",sqlp,conn);
			//to get the query string
			String Max_Val_Query=sqlp.getProperty("Char_Query_Name","");
			str=rsSch.extractVal("Tinyint_Tab",1,sqlp,conn); 
			String sPrepStatement=sqlp.getProperty("Char_Tab_Name_Update",null);
			pstmt = conn.prepareStatement(sPrepStatement);
			pstmt.setString(1,str);
			pstmt.executeUpdate();
			maxByteVal = Byte.parseByte(str);
			rs=stmt.executeQuery(Max_Val_Query);
			rsmd=rs.getMetaData();
			rs.next();
			logMsg("Calling getByte on Char_Tab");
			columname=rsmd.getColumnName(1);
			retValue=rs.getByte(columname);
			if(maxByteVal==retValue)
			{
				logMsg("getByte method returns : "+ retValue);
			}
			else
			{
				logErr("getByte method does not return the maximum value from Char Table ");
				throw new Fault("Call to getByte is Failed!");
			}
		}
		
		catch(SQLException sqle)
		{
			logErr("SQL Exception " + sqle.getMessage() );
			throw new Fault("Call to getByte is Failed!", sqle);
		}
		catch(Exception e)
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Fault("Call to getByte is Failed!", e);
		}
		finally
		{
			try
			{
			pstmt.close();
			rs.close();
			rsSch.dropTab("Char_Tab",conn);
			}
			catch (Exception e) {};
		}

		
	}


	
	
	/* @testName:       testGetByte71
	 *                    
	 * @assertion:      The ResultSet object contains the results of executing an 
	 *                  SQL Query.  ResultSets may hava different levels of functionality 
	 *                  (ResultSet Types TYPE_FORWARD_ONLY, TYPE_SCROLL_SENSITIVE, 
	 *                  TYPE_SCROLL_INSENSITIVE) and update capabilities (ResultSet 
	 *                  Concurrency). (See section 26.1 of JDBC 2.0 API Reference 
	 *                  & Tutorial second edition).  The JDBC driver must provide full 
	 *                  support for TYPE_SCROLL_INSENSITIVE result sets. (See section 
	 *                  6.2.2.3 of Java2 Platform Enterprise Edition Specification v1.2)
	 *                  The getByte(String columnName) gets the value of the designated column in 
	 *                  the current row of this ResultSet object as a byte in the Java programming
	 *                  language; if the value is SQL NULL, the value returned is 0.
	 *
	 * @test_Strategy:  Get a PreparedStatement object from the connection to the database.
	 *                  Using this,update the table Char_Tab with the minimum value of 
	 *                  table Tinyint_Tab.Now execute a query to get that value from
	 *                  Char_Tab table and retrieve the result of the query using the 
	 *                  getByte(String columnName) method.Compare the returned value, with the 
	 *                  minimum value of table Tinyint_Tab extracted from the ctssql.stmt file.
	 *                  Both of them should be equal.   
	 */
	public void testGetByte71() throws Fault
	{
		byte retValue;
		byte minByteVal;
		String str =null;
		ResultSet rs = null;
		ResultSetMetaData rsmd=null;
		String columname=null;
		try
		{
			rsSch.createTab("Char_Tab",sqlp,conn);
			//to get the query string
			String Min_Val_Query=sqlp.getProperty("Char_Query_Name","");
			str=rsSch.extractVal("Tinyint_Tab",2,sqlp,conn); 
			String sPrepStatement=sqlp.getProperty("Char_Tab_Name_Update",null);
			pstmt = conn.prepareStatement(sPrepStatement);
			pstmt.setString(1,str);
			pstmt.executeUpdate();
			minByteVal = Byte.parseByte(str);
			rs=stmt.executeQuery(Min_Val_Query);
			rsmd=rs.getMetaData();
			rs.next();
			logMsg("Calling getByte on Char_Tab");
			columname=rsmd.getColumnName(1);
			retValue=rs.getByte(columname);
			if(minByteVal==retValue)
			{
				logMsg("getByte method returns : "+ retValue);
			}
			else
			{
				logErr("getByte method does not return the minimum value from Char Table ");
				throw new Fault("Call to getByte is Failed!");
			}
		}
		
		catch(SQLException sqle)
		{
			logErr("SQL Exception " + sqle.getMessage() );
			throw new Fault("Call to getByte is Failed!", sqle);
		}
		catch(Exception e)
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Fault("Call to getByte is Failed!", e);
		}
		finally
		{
			try
			{
				pstmt.close();
				rs.close();
				rsSch.dropTab("Char_Tab",conn);
			}catch (Exception e) {};
		}

		
	}


	
	/* @testName:       testGetByte72
	 *                    
	 * @assertion:      The ResultSet object contains the results of executing an 
	 *                  SQL Query.  ResultSets may hava different levels of functionality 
	 *                  (ResultSet Types TYPE_FORWARD_ONLY, TYPE_SCROLL_SENSITIVE, 
	 *                  TYPE_SCROLL_INSENSITIVE) and update capabilities (ResultSet 
	 *                  Concurrency). (See section 26.1 of JDBC 2.0 API Reference 
	 *                  & Tutorial second edition).  The JDBC driver must provide full 
	 *                  support for TYPE_SCROLL_INSENSITIVE result sets. (See section 
	 *                  6.2.2.3 of Java2 Platform Enterprise Edition Specification v1.2)
	 *                  The getByte(String columnName) gets the value of the designated column in 
	 *                  the current row of this ResultSet object as a byte in the Java programming
	 *                  language; if the value is SQL NULL, the value returned is 0.
	 *
	 * @test_Strategy:  Get a ResultSet object by executing the query that returns null value
	 *                  from table Char_Tab.Call the getByte(String columnName) method.Check if the value 
	 *                  returned is zero.
     */
	public void testGetByte72() throws Fault
	{
		byte retValue;
		String snullByteVal =null;
		ResultSet rs = null;
		ResultSetMetaData rsmd=null;
		String columname=null;
		try
		{
			rsSch.createTab("Char_Tab",sqlp,conn);
			//to get the query string
			String Null_Val_Query=sqlp.getProperty("Char_Query_Null","");
			rs=stmt.executeQuery(Null_Val_Query);
			rsmd=rs.getMetaData();
			rs.next();
			logMsg("Calling  getByte on Char_Tab");
			columname=rsmd.getColumnName(1);
			retValue=rs.getByte(columname);
			
			if(retValue == 0)
			{
				logMsg("Calling getByte method on a SQL Null column returns"+retValue);
			}
			else
			{
				logErr("getByte method does not return the value zero ");
				throw new Fault("Call to getByte is Failed!");
			}
			
		}
		catch(SQLException sqle)
		{
			logErr("SQL Exception " + sqle.getMessage() );
			throw new Fault("Call to getByte is Failed!", sqle);
		}
		catch(Exception e)
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Fault("Call to getByte is Failed!", e);
		}
		finally
		{
		try {
		    rs.close();
		    rsSch.dropTab("Char_Tab",conn);
		  } catch (Exception e) {};
		}
	}


	
	/* @testName:       testGetByte73
	 *                    
	 * @assertion:      The ResultSet object contains the results of executing an 
	 *                  SQL Query.  ResultSets may hava different levels of functionality 
	 *                  (ResultSet Types TYPE_FORWARD_ONLY, TYPE_SCROLL_SENSITIVE, 
	 *                  TYPE_SCROLL_INSENSITIVE) and update capabilities (ResultSet 
	 *                  Concurrency). (See section 26.1 of JDBC 2.0 API Reference 
	 *                  & Tutorial second edition).  The JDBC driver must provide full 
	 *                  support for TYPE_SCROLL_INSENSITIVE result sets. (See section 
	 *                  6.2.2.3 of Java2 Platform Enterprise Edition Specification v1.2)
	 *                  The getByte(String columnName) gets the value of the designated column in 
	 *                  the current row of this ResultSet object as a byte in the Java programming
	 *                  language; if the value is SQL NULL, the value returned is 0.
	 *
	 * @test_Strategy:  Get a PreparedStatement object from the connection to the database.
	 *                  Using this,update the table Varchar_Tab with the maximum value of 
	 *                  table Tinyint_Tab.Now execute a query to get that value from
	 *                  Varchar_Tab table and retrieve the result of the query using the 
	 *                  getByte(String columnName) method.Compare the returned value, with the 
	 *                  maximum value of table Tinyint_Tab extracted from the ctssql.stmt file.
	 *                  Both of them should be equal.
	 */
	public void testGetByte73() throws Fault
	{
		byte retValue;
		byte maxByteVal;
		String str =null;
		ResultSet rs = null;
		ResultSetMetaData rsmd=null;
		String columname=null;
		try
		{
			rsSch.createTab("Varchar_Tab",sqlp,conn);
			//to get the query string
			String Max_Val_Query=sqlp.getProperty("Varchar_Query_Name","");
			str=rsSch.extractVal("Tinyint_Tab",1,sqlp,conn); 
			String sPrepStatement=sqlp.getProperty("Varchar_Tab_Name_Update",null);
			pstmt = conn.prepareStatement(sPrepStatement);
			pstmt.setString(1,str);
			pstmt.executeUpdate();
			maxByteVal = Byte.parseByte(str);
			rs=stmt.executeQuery(Max_Val_Query);
			rsmd=rs.getMetaData();
			rs.next();
			logMsg("Calling getByte on Varchar_Tab");
			columname=rsmd.getColumnName(1);
			retValue=rs.getByte(columname);
			if(maxByteVal==retValue)
			{
				logMsg("getByte method returns : "+ retValue);
			}
			else
			{
				logErr("getByte method does not return the maximum value from Varchar Table ");
				throw new Fault("Call to getByte is Failed!");
			}
		}
		
		catch(SQLException sqle)
		{
			logErr("SQL Exception " + sqle.getMessage() );
			throw new Fault("Call to getByte is Failed!", sqle);
		}
		catch(Exception e)
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Fault("Call to getByte is Failed!", e);
		}
		finally
		{
			try
			{
				pstmt.close();
				rs.close();
				rsSch.dropTab("Varchar_Tab",conn);
			}
			catch (Exception e) {};
		}

		
	}


	/* @testName:       testGetByte74
	 *                    
	 * @assertion:      The ResultSet object contains the results of executing an 
	 *                  SQL Query.  ResultSets may hava different levels of functionality 
	 *                  (ResultSet Types TYPE_FORWARD_ONLY, TYPE_SCROLL_SENSITIVE, 
	 *                  TYPE_SCROLL_INSENSITIVE) and update capabilities (ResultSet 
	 *                  Concurrency). (See section 26.1 of JDBC 2.0 API Reference 
	 *                  & Tutorial second edition).  The JDBC driver must provide full 
	 *                  support for TYPE_SCROLL_INSENSITIVE result sets. (See section 
	 *                  6.2.2.3 of Java2 Platform Enterprise Edition Specification v1.2)
	 *                  The getByte(String columnName) gets the value of the designated column in 
	 *                  the current row of this ResultSet object as a byte in the Java programming
	 *                  language; if the value is SQL NULL, the value returned is 0.
	 *
	 * @test_Strategy:  Get a PreparedStatement object from the connection to the database.
	 *                  Using this,update the table Varchar_Tab with the minimum value of 
	 *                  table Tinyint_Tab.Now execute a query to get that value from
	 *                  Varchar_Tab table and retrieve the result of the query using the 
	 *                  getByte(String columnName) method.Compare the returned value, with the 
	 *                  minimum value of table Tinyint_Tab extracted from the ctssql.stmt file.
	 *                  Both of them should be equal.   
	 */
	public void testGetByte74() throws Fault
	{
		byte retValue;
		byte minByteVal;
		String str =null;
		ResultSet rs = null;
		ResultSetMetaData rsmd=null;
		String columname=null;
		try
		{
			rsSch.createTab("Varchar_Tab",sqlp,conn);
			//to get the query string
			String Min_Val_Query=sqlp.getProperty("Varchar_Query_Name","");
			str=rsSch.extractVal("Tinyint_Tab",2,sqlp,conn); 
			String sPrepStatement=sqlp.getProperty("Varchar_Tab_Name_Update",null);
			pstmt = conn.prepareStatement(sPrepStatement);
			pstmt.setString(1,str);
			pstmt.executeUpdate();
			minByteVal = Byte.parseByte(str);
			rs=stmt.executeQuery(Min_Val_Query);
			rsmd=rs.getMetaData();
			rs.next();
			logMsg("Calling getByte on Varchar_Tab");
			columname=rsmd.getColumnName(1);
			retValue=rs.getByte(columname);
			if(minByteVal==retValue)
			{
				logMsg("getByte method returns : "+ retValue);
			}
			else
			{
				logErr("getByte method does not return the  minimum value from Varchar Table ");
				throw new Fault("Call to getByte is Failed!");
			}
		}
		
		catch(SQLException sqle)
		{
			logErr("SQL Exception " + sqle.getMessage() );
			throw new Fault("Call to getByte is Failed!", sqle);
		}
		catch(Exception e)
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Fault("Call to getByte is Failed!", e);
		}
		finally
		{
			try
			{
				pstmt.close();
				rs.close();
				rsSch.dropTab("Varchar_Tab",conn);
			}catch (Exception e) {};
		}

		
	}


	/* @testName:       testGetByte75
	 *                    
	 * @assertion:      The ResultSet object contains the results of executing an 
	 *                  SQL Query.  ResultSets may hava different levels of functionality 
	 *                  (ResultSet Types TYPE_FORWARD_ONLY, TYPE_SCROLL_SENSITIVE, 
	 *                  TYPE_SCROLL_INSENSITIVE) and update capabilities (ResultSet 
	 *                  Concurrency). (See section 26.1 of JDBC 2.0 API Reference 
	 *                  & Tutorial second edition).  The JDBC driver must provide full 
	 *                  support for TYPE_SCROLL_INSENSITIVE result sets. (See section 
	 *                  6.2.2.3 of Java2 Platform Enterprise Edition Specification v1.2)
	 *                  The getByte(String columnName) gets the value of the designated column in 
	 *                  the current row of this ResultSet object as a byte in the Java programming
	 *                  language; if the value is SQL NULL, the value returned is 0.
	 *
	 * @test_Strategy:  Get a ResultSet object by executing the query that returns null value
	 *                  from table Varchar_Tab.Call the getByte(String columnName) method.Check if the value 
	 *                  returned is zero.
	 */
	public void testGetByte75() throws Fault
	{
		byte retValue;
		String snullByteVal =null;
		ResultSet rs = null;
		ResultSetMetaData rsmd=null;
		String columname=null;
		try
		{
			rsSch.createTab("Varchar_Tab",sqlp,conn);
			//to get the query string
			String Null_Val_Query=sqlp.getProperty("Varchar_Query_Null","");
			rs=stmt.executeQuery(Null_Val_Query);
			rsmd=rs.getMetaData();
			rs.next();
			logMsg("Calling  getByte on Varchar_Tab");
			columname=rsmd.getColumnName(1);
			retValue=rs.getByte(columname);
			
			if(retValue == 0)
			{
				logMsg("Calling getByte method on a SQL Null column returns"+retValue);
			}
			else
			{
				logErr("getByte method does not return the value zero ");
				throw new Fault("Call to getByte is Failed!");
			}
			
		}
		catch(SQLException sqle)
		{
			logErr("SQL Exception " + sqle.getMessage() );
			throw new Fault("Call to getByte is Failed!", sqle);
		}
		catch (Exception e)
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Fault("Call to getByte is Failed!", e);
		}
		finally
		{
			try{
				rs.close();
				rsSch.dropTab("Varchar_Tab",conn);
			} catch (Exception e) {};
		}
	}


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