Re: [GENERAL] JDBC and insert - stack overflow

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: crispin(at)cs(dot)man(dot)ac(dot)uk
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: [GENERAL] JDBC and insert - stack overflow
Date: 1999-05-25 10:24:24
Message-ID: l03130305b36f3179590d@[147.233.159.109]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-interfaces

At 17:09 +0300 on 24/05/1999, Crispin Miller wrote:

> Hi,
> I am afraid I am a newbie. Forgive me if this is a silly question-
> I'm trying to create a large database using JDBC to load the tables by
> calling executeUpdate with the statement "SQL INSERT INTO" + tableName +
> " VALUES (" etc...

JDBC questions belong in the Interfaces list, where I have now redirected
this thread.

The proper way to perform inserts is using a PreparedStatement, like this:

PreparedStatement pstmt = con.prepareStatement(
"INSERT INTO my_table (num,str,dt) VALUES (?,?,?)"
);

Then you loop, and in each iteration you do:

pstmt.setInt( 1, myIntVariable);
pstmt.setString( 2, myStringVariable);
pstmt.setDate( 3, mySQLDateVariable);

int rowCount = pstmt.executeUpdate();

Try this method. I'm not sure it will solve your stack problems. Usually,
stack overflow is due to deep recursion. But once you use this, you should
be wasting less memory anyway.

By the way, use con.setAutoCommit( false ) to have all the inserts in one
big transaction. It saves a lot of time.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Wheeler, Alfred 1999-05-25 14:32:21 unsubscribe pgsql-general
Previous Message jerome doucerain 1999-05-25 10:11:24 Re: [GENERAL] Archive logging

Browse pgsql-interfaces by date

  From Date Subject
Next Message Alex Turner 1999-05-25 11:52:34 Retreiving Table info
Previous Message Herouth Maoz 1999-05-25 09:45:16 Re: [INTERFACES] Questions about INSERT INTO!