import java.sql.*;

public class RepeatStatement {

    public static void main(String[] args) throws Exception{
	Class.forName("org.apache.derby.jdbc.ClientDriver");
	String url = "jdbc:derby://localhost/testdb;create=true";
	Connection conn = DriverManager.getConnection(url);
	for (int i = 1; i < 32000; i++)
	    testInsertAndSelect(conn);
    }

    public static void testInsertAndSelect(Connection conn) throws SQLException
    {

	Statement s = conn.createStatement();
	try {
	    s.executeUpdate("DROP TABLE TAB");
	} catch (SQLException se)
	    {
		//ignore table not found exception
	    }
	
	s.executeUpdate("CREATE TABLE TAB (col1 varchar(32672))");
	PreparedStatement ps = conn.prepareStatement("INSERT INTO TAB VALUES(?)");
	ps.setString(1,"hello");
        ps.executeUpdate();
	ps.setString(1,"hello");
	ps.executeUpdate();
        
	ResultSet rs = s.executeQuery("SELECT * from tab");
	// drain the resultset
	while (rs.next());
        // If I don't explicitly close the resultset or 
        // statement, we get a leak.
        //rs.close();
        //s.close();
        ps.close();
	    
    }




}
