1

I have a large data set(250,000 rows) that I need to upload to a SQL table. I am currently doing this from a Java application I created, and as expected, it is extremely slow. I have to insert each row from a text file into a table, with an auto_increment column that stores an id for that new row. Now I want to use that same id to insert a modified version of the string I entered to the first table, into a second table, where one of the columns holds that original incremented id, so that I can tie the two rows together. Obviously I can query the string I just inserted, and pull the id, but that is an extra query per row I'm trying to avoid. Is there a way to pull the incremented id value from the sql table to my java class at the time the insert statement is executed?

Thanks,

3
  • Which database server are you using? Commented Aug 10, 2012 at 23:48
  • its a SQL database running on a RDS instance on Amazon AWS. Does that help? Commented Aug 10, 2012 at 23:57
  • Unfortunately, it doesn't. RDS is just an interface to an instance of a RDBMS, and all RDBMS use SQL, but the way to retrieve the ID of a newly inserted row changes greatly between them. I'd suggest that you find out if the DB Server you connect to is SQL Server, MySQL, Oracle, PostgreSQL or something else. Commented Aug 11, 2012 at 1:32

1 Answer 1

1

I guess you are using JDBC so use getGeneratedKeys() of java.sql.PreparedStatement. The returned Resulset contains the auto-generated key.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.