• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it possible or not?

 
Gaurav Chikara
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have a vector of vectors
now each vector element of the parent vector contains a record
i want that all vector elements .i.e records shud be inserted into database at one go I mean
Is it possible to insert multiple records at same time
because insert statement inserts only one record at a time
and statement only will insert one record at a time
and on submit of form i want all records to be inserted
Can anyone pls throw some light on it
Thankx in advance
Gaurav
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See java.sql.Statement.addBatch(), java.sql.Statement.executeBatch().
HTH
- Peter
 
Gaurav Chikara
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI peter
thnkx for ur reply
but in my case i hvae to use same statement for inserting records in the db
and unless we commit first insert we cannot insert next statement
as it locks the row in which we intend to insert
i hope u get wht i m trying to explain
any other views r most welcome
Gaurav
Originally posted by Peter den Haan:
See java.sql.Statement.addBatch(), java.sql.Statement.executeBatch().
HTH
- Peter

 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gaurav Chikara:
in my case i hvae to use same statement for inserting records in the db
and unless we commit first insert we cannot insert next statement
as it locks the row in which we intend to insert
i hope u get wht i m trying to explain

Sorry, but I do not quite get it. All the inserts are part of the same transaction, so the locks you acquire are irrelevant.
Anyway, addBatch() is AFAIK the only way to efficiently execute a batch of statements in JDBC.
- Peter
 
Ajay Singhal
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi! friends
as u r trying to store vectors in database. can i store my java object in database like Emp.
if yes pls. specify how!!!
Ajay Singhal
 
Gaurav Chikara
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at Blob and Clob data types
they will help u
Originally posted by Ajay Singhal:
hi! friends
as u r trying to store vectors in database. can i store my java object in database like Emp.
if yes pls. specify how!!!
Ajay Singhal


[This message has been edited by Gaurav Chikara (edited February 05, 2001).]
 
stucko stuck
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i too have the same problem,
i want to insert a number og records from a table into another table.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"stucko stuck",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by stucko stuck:
i too have the same problem,
i want to insert a number og records from a table into another table.


how about insert as select.
 
Gaurav Chikara
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter den Haan did replied to this query a couple of years back and he was right.I dont know what you meant by
"How about insert as select"
[ November 26, 2004: Message edited by: Gaurav Chikara ]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34860
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gaurav,
Most databases allow a statement like this:

It lets you insert data into a table directly from another query.
 
Gaurav Chikara
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeanne Boyarsky:
Gaurav,
Most databases allow a statement like this:

It lets you insert data into a table directly from another query.


But here we were talking about using JDBC and not using DML statements in some databases.I am sure DB2 doesn't allow it
Never mind Thanks for remark
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34860
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gaurav,
You can do anything in JDBC that the underlying database lets you do in DML. (given that it isn't portable.)

I think you are correct that db2 doesn't support it though.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gaurav Chikara:
Peter den Haan did replied to this query a couple of years back and he was right.I dont know what you meant by
"How about insert as select"


I just replied to stucko stuck's question. I dont know why that mate didn't make a new thread.

anyways, sorry for confusion.
thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic