	

	/**

		This is the main method of the loader. It reads a file, puts some attributes into a simple
		container and calls two insert methods for two tables.
		Called with an input file of 5000 records, the method performs 10.000 inserts and takes about
		13 seconds for this job. The executing computer is a IBM R60 Thinkpad Laptop with 3 GB Ram 
		running Windows XP Professional. The database is installed on the same machine. 
	 */
	public boolean load() {
		Out.out("Jdbc URL: " + jdbcURL);
		Out.out("Datei   : " + schuldnerFile);
		boolean b = true;
		
		if (!connect()) {
			Out.out("Cound not connect to: " + this.jdbcURL);
			return false;
		}
		Out.out("Connect hergestellt...");
		Date von = new Date();
		
		jdbcLoader = new JDBCLoader(conn);
		
		/*String sFile = "inserts.sql";
		if (!this.openFile4Output(sFile))
			return false;
		*/
		
		// jetzt die schuldner lesen und dann laden
		int count = 0;
		try {
			long idp;
			FileReader reader = new FileReader();
			reader.open(schuldnerFile);
			String schuldner = reader.nextLine();
			while (b == true && schuldner != null && schuldner.length() > 0) {
				count++;
				idp = insertPersonMitNextId(schuldner,count);
				NatuerlichePersonDTO natPers = new NatuerlichePersonDTO();
				natPers.setPersonID(idp);
				natPers.setVorname("Person " + count);
				this.insertNatPersonMitNextId(natPers, count);
				conn.commit();
				schuldner = reader.nextLine();
			}
			
			/*for (int i = 0; i < 10000;i++) {
				insertPersonMitNextId(">>" + i,i);
				//writeit(i);
			}*/
			//writer.close();
		}
		catch (Exception ex) {
			System.out.println("Fehler in Verarbeitungsschleife:" + ex.getMessage());
			b = false;
		}
		
		Date bis = new Date();
		
		Out.out("Nach Schleife, b=" + b);
		Out.out("count=" + count);
		// disconnect from database 
		try {
			if (count > 0) {
				if (b)
					conn.commit();
				else
					conn.rollback();
			}
			conn.close();
			Out.out("Jdbc Verbindung abgebaut....");
		}
		catch (Exception ex) {
    		Out.out("Fehler bei Datenbankoperation: " + ex.getMessage());
    		return false;
		}
		
		System.out.println("Zeit von:" + von);
		System.out.println("Zeit bis:" + bis);
		System.out.println("absolut :" + (bis.getTime() - von.getTime()));
		Date inSek = new Date(bis.getTime() - von.getTime());
		System.out.println("in Min/Sek:" + inSek.getMinutes() + "/" + inSek.getSeconds());
		
		
		return b;
	}






	protected long insertPersonMitNextId(String schuldner, int index) throws Exception {
		
		StringTokenizer st = new StringTokenizer(schuldner,"$");
		st.nextToken();
		String name = st.nextToken();
		
		if (index % 200 == 0)
			System.out.println(index + " >> " + name); 
		
		if (stmtInsertPerson == null) {
			System.out.println("$$ create statement person...");
			insertPerson = "insert into myschema.person(id,name,phonetischer_diskriptor_name, historie_fk,persontyp) values(?,?,?,?,?)";
			try {
				stmtInsertPerson = conn.prepareStatement(insertPerson);
			}
			catch (Exception ex) {
				Out.out("Fehler bei prepare statement: " + ex.getMessage());
				throw ex;
				
			}
		}
		
		// insert statement vorbereiten
		try {
			long id = this.jdbcLoader.nextIdMitPrep(conn,"person",index);
			//System.out.println(" $$ personid bei insert person = " +  id);
			stmtInsertPerson.setLong(1, id);
			stmtInsertPerson.setString(2, name);
			stmtInsertPerson.setString(3,"egal"); // $$TODO phonetischer_deskriptor_name
			stmtInsertPerson.setLong(4, HISTORIE_ID); // $$TODO 
			stmtInsertPerson.setInt(5,1); // personTyp = 1
			stmtInsertPerson.execute();
			return id;
		}
		catch (Exception ex) {
			Out.out("Fehler bei execute insert person: " + ex.getMessage());
			throw ex;
		}
	}
	
	
	
	/**
	 * Datensatz in Tabelle person einfgen
	 * 
	 * @param schuldner
	 * 
	 * @throws Exception
	 */
	protected long insertNatPersonMitNextId(NatuerlichePersonDTO schuldner, int index) throws Exception {
		
		if (stmtInsertNatPerson == null) {
			System.out.println("$$ create statement natperson...");
			insertNatPerson = "insert into myschema.natuerliche_person(id,person_fk, vorname, norm_vorname) values(?,?,?,?)";
			try {
				stmtInsertNatPerson = conn.prepareStatement(insertNatPerson);
			}
			catch (Exception ex) {
				Out.out("Fehler bei prepare statement: " + ex.getMessage());
				throw ex;
				
			}
		}
		
		// insert statement vorbereiten
		try {
			String name = schuldner.getVorname();
			if (name.length() > 60)
				name = name.substring(0, 60);
			long id = jdbcLoader.nextIdMitPrep(conn,"natuerliche_person",index);
			stmtInsertNatPerson.setLong(1, id);
			//System.out.println(" $$ personid bei insert nat person = " +  schuldner.getPersonID());
			stmtInsertNatPerson.setLong(2, schuldner.getPersonID());
			stmtInsertNatPerson.setString(3,name);
			stmtInsertNatPerson.setString(4, name.toUpperCase()); 
			stmtInsertNatPerson.execute();
			return id;
		}
		catch (Exception ex) {
			Out.out("Fehler bei execute insert natuerliche_person: " + ex.getMessage());
			throw ex;
		}
	}
		
	

The nextId method which is used:
	
	/**
	 * @throws Exception
	 */
	public long  nextIdMitPrep(Connection conn, String table, int index) throws Exception {
		//System.out.println("nextid von:" + table);

		if (stmtNextId== null) {
			nextId = "select nextval(?)";
			try {
				stmtNextId = conn.prepareStatement(nextId);
				//System.out.println(" $$ prepared Statement for:" + nextId);
			}
			catch (Exception ex) {
				Out.out("Fehler bei prepare nextId statement: " + ex.getMessage());
				throw ex;
				
			}
		}

		
		// insert statement vorbereiten
		try {
			stmtNextId.setString(1, "myschema." + table + "_id_seq");
			ResultSet rs = stmtNextId.executeQuery();
			//System.out.println(" $$ resultSet=" + rs);
			rs.next();
			long id = rs.getLong(1);
			if (index % 200 == 0)	
				System.out.println(" $$ id = " + id);
			return id;
		}
		catch (Exception ex) {
			Out.out("Fehler bei execute next id statement: " + ex.getMessage());
			throw ex;
		}
		

	}
	


And this are the tables:
drop schema if exists myschem cascade;

create schema myschema;


drop table if exists myschema.person;
CREATE TABLE myschema.PERSON (
       ID                   						bigserial not null		PRIMARY KEY,
       NAME                 						varchar(60) not null,
--       NORM_NAME               						varchar(60),
       PHONETISCHER_DISKRIPTOR_NAME 				varchar(120) not null,
       --ANSCHRIFT_fk          						bigint,
--       BEMERKUNG            						varchar(512),
--       VORGAENGER_VERSION_fk 						bigint,
--       VERMOEGENSVERZEICHNIS_fk						bigint,
       HISTORIE_fk           						bigint not null,
       PERSONTYP									integer not null
)
;





drop TABLE if exists myschema.NATUERLICHE_PERSON;
CREATE TABLE myschema.NATUERLICHE_PERSON (
       ID                   						bigserial not null PRIMARY KEY,
       PERSON_fk            						bigint not null,
       VORNAME              						varchar(60),
       NORM_VORNAME            						varchar(60),
       ANREDE               						varchar(2),
       BRIEF_ANREDE         						varchar(2),
       TITEL                						varchar(2),
       AMTSBEZEICHNUNG      						varchar(2),
       NAMENSZUSATZ         						varchar(10),
       SONSTIGERNAME          						varchar(60),
	   NORM_SONSTIGERNAME    			            varchar(60),
       GEBURTSNAME          						varchar(60),
	   NORM_GEBURTSNAME    							varchar(60),
       GEBURTSDATUM         						date,
       GEBURTSORT           						varchar(60),
       GEBURTSSTAAT         						varchar(2),
       GESCHLECHT           						char(1),
       STAATSANGEHOERIGKEIT 						varchar(2)
);
