import java.io.*;
import java.sql.*;
import java.util.*;

public class TestHSQLDB
{
	public static void main( String[] args )
	{
		Connection con = null;

		try
		{
			Class.forName( "org.hsqldb.jdbcDriver" );
			
			con = DriverManager.getConnection( "jdbc:hsqldb:.", "sa", "" );

			initTable( con );
			loadTable( con );

			con.commit();
		}
		catch( Exception e )
		{
			e.printStackTrace();
		}
	}


	private static void initTable( Connection con )
	{
		Statement stmt = null;

		try
		{
			String cols = "";
			for( int i = 0; i < 60; i++ )
			{
				cols += "col"+i+" char(5) not null";
				if( i < 59 )
					cols+=",";
			}
			
			System.out.println( "create table test ( "+cols+")" );
			stmt = con.createStatement();
			stmt.execute( "create table test ( "+cols+")" );
		}
		catch( SQLException sqle )
		{
			sqle.printStackTrace();
		}
		finally
		{
			if( stmt != null )
			{
				try
				{
					stmt.close();
				}
				catch(SQLException ignored){}
			}
		}
	}


	private static void loadTable2( Connection con )
	{
		PreparedStatement pStmt = null;
		try
		{
			String cols = "";
			for( int i = 0; i < 60; i++ )
			{
				cols += "'AAAAA'";
				if( i < 59 )
					cols+=",";
			}
			
			System.out.println( "insert into test values ( "+cols+")" );
			
			pStmt = con.prepareStatement("insert into test values ( "+cols+")");
			for( int i = 0; i < 100000; i++ )
			{
				pStmt.addBatch();
			}

			pStmt.executeBatch();
		}
		catch( SQLException sqle )
		{
			sqle.printStackTrace();
		}
		finally
		{
			if( pStmt != null )
			{
				try
				{
					pStmt.close();
				}
				catch(SQLException ignored){}
			}
		}
	}

	private static void loadTable( Connection con )
	{
		Statement stmt = null;

		try
		{
			String cols = "";
			for( int i = 0; i < 60; i++ )
			{
				cols += "'AAAAA'";
				if( i < 59 )
					cols+=",";
			}
			
			System.out.println( "insert into test values ( "+cols+")" );
			
			stmt = con.createStatement();
			for( int i = 0; i < 100000; i++ )
			{
				stmt.executeUpdate("insert into test values ( "+cols+")");
				if( i != 0 && ( i % 1000 == 0 ) )
					System.out.println( "Loaded: " +i);
			}
		}
		catch( SQLException sqle )
		{
			sqle.printStackTrace();
		}
		finally
		{
			if( stmt != null )
			{
				try
				{
					stmt.close();
				}
				catch(SQLException ignored){}
			}
		}
	}
}