import java.sql.*;
import java.util.*;
import com.informix.jdbc.*;
import com.informix.lang.IfxTypes;
 
public class smalltest
{
    String url = null;
    
    Connection conn = null;
    
    public static void main (String args[])
    {
        new smalltest(args);
    }
    
    smalltest(String args[])
    {
        Statement stmt = null;
	// -----------
        // Getting URL
        // -----------
        if (args.length == 0)
            {
		System.out.println("ERROR: connection URL must be provided in " +
				   "order to run the demo!");
		return;
            }
        url = args[0];
	
	// --------------
        // Loading driver
        // --------------
	try
            {
		Class.forName("com.informix.jdbc.IfxDriver");
            }
        catch (java.lang.ClassNotFoundException e)
            {
		System.out.println("\n***ERROR: " + e.getMessage());
		e.printStackTrace();
		return;
            }
        // ------------------
        // Getting connection
        // ------------------
	try
            {
		conn = DriverManager.getConnection(url);
            }
        catch (SQLException e)
            {
		System.out.println("URL = \"" + url + "\"");
		System.out.println("\n***ERROR: " + e.getMessage());
		e.printStackTrace();
		return;
            }	
        // ------------------
        // Setting up typemap
        // ------------------
        try
            {
		java.util.Map customtypemap = conn.getTypeMap();
		if (customtypemap == null)
		    {
			System.out.println("\n***ERROR: typemap is null!");
			return;
		    }
		customtypemap.put("myint", Class.forName("myint"));
		customtypemap.put("a_ty", Class.forName("a_ty"));
		customtypemap.put("b_ty", Class.forName("b_ty"));
            }
        catch (ClassNotFoundException e)
            {
		System.out.println("\n***ERROR: " + e);
            }
        catch (SQLException e)
            {
		System.out.println("\n***ERROR: " + e.getErrorCode() + " " +
                                   e.getMessage());
		e.printStackTrace();
		return;
            }
	try
            {
		// This statement works fine. But there is no table under b_ta!
		stmt = conn.createStatement();
		ResultSet rs = stmt.executeQuery("select b_ta from b_ta");
		while (rs.next())
		    {
			b_ty val1 =(b_ty)rs.getObject(1);
			System.out.println("Value b_ty : " + val1);
		    }
		stmt.close();
            }
	catch (SQLException e)
	    {
		System.out.println("***ERROR: " + e.getErrorCode() + " " +          
				   e.getMessage());
		e.printStackTrace();
	    }
	System.out.println();
	
	try
            {
		// This statement works with 9.20.UC2 but not with 9.21.UC1
		stmt = conn.createStatement();
		ResultSet rs = stmt.executeQuery("select a_ta from a_ta");
		while (rs.next())
		    {
			a_ty val2 =(a_ty)rs.getObject(1);
			System.out.println("Value a_ty: " + val2);
		    }
		stmt.close();
            }
	catch (SQLException e)
	    {
		System.out.println("***ERROR: " + e.getErrorCode() + " " +          
				   e.getMessage());
		e.printStackTrace();
	    }
	System.out.println();
	
		

		

    }
}
