import java.sql.*;

public class TestBoundaries {

    public static String FIFTEEN_THOUSAND_STRING = null;
    public static void main(String[] args) throws Exception{
	FIFTEEN_THOUSAND_STRING = repeatChar("a",15000);
	Class.forName("org.apache.derby.jdbc.ClientDriver");
	String url = "jdbc:derby://localhost:1528/testdb;create=true";
	Connection conn = DriverManager.getConnection(url);
	for (int i = 1; i < 32000; i++)
	    {
		Statement s = conn.createStatement();
		try {
		    s.executeUpdate("DROP TABLE TAB");
		} catch (SQLException se)
		    {
			//ignore table not found exception
		    }
		System.out.println("datasize:" + (30000 + i));
		s.executeUpdate("CREATE TABLE TAB (col1 varchar(32672) NOT NULL)");
		PreparedStatement ps = conn.prepareStatement("INSERT INTO TAB VALUES(?)");
		ps.setString(1,FIFTEEN_THOUSAND_STRING);
		ps.executeUpdate();
		ps.setString(1,FIFTEEN_THOUSAND_STRING);
		ps.executeUpdate();
		ps.setString(1,repeatChar("c",i));
		ps.executeUpdate();
        
		ResultSet rs = s.executeQuery("SELECT * from tab");
		// drain the resultset
		while (rs.next())
		    {
			rs.getString(1);
		    }
		rs.close();
		s.close();
		ps.close();
	    }
    }
	


/**
    	 * repeatChar is used to create strings of varying lengths.
    	 * called from various tests to test edge cases and such.
    	 *
    	 * @param c             character to repeat
    	 * @param repeatCount   Number of times to repeat character
    	 * @return              String of repeatCount characters c
    	 */
       public static String repeatChar(String c, int repeatCount)
       {
    	   char ch = c.charAt(0);

    	   char[] chArray = new char[repeatCount];
    	   for (int i = 0; i < repeatCount; i++)
    	   {
    		   chArray[i] = ch;
    	   }

    	   return new String(chArray);

       }

}
