ageoff
ageoff

Reputation: 2828

Insert into SQL Derby using column indices instead of column names

Is there any way to insert into a Derby database in java by using the column index instead of the column name?

Example:

INSERT INTO myTable (5) values ('PUT THIS IN COLUMN INDEX 5')

Where 5 is the index of a column, not the column name.

Upvotes: 2

Views: 374

Answers (2)

hd1
hd1

Reputation: 34657

Use an updatable resultset and named columns:

ResultSet updates = connectionObject.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE).executeQuery("select id, foo1, foo2 from footable);
updates.moveToInsertRow();
updates.updateInt(1, 34); // updates id
updates.updateString(2, "bar"); // updates foo1
updates.updateBoolean(3, true); // updates foo2
updates.insertRow();
connectionObject.commit();

I hope this helped, if you have further questions, do leave a comment.

Upvotes: 2

Marco Forberg
Marco Forberg

Reputation: 2644

according to the documentation the insert statement only supports column names not indexes. (took me less then 5s to google that)

Upvotes: 0

Related Questions