Solved

Can i get any result back from the insert Query?

Posted on 2003-11-05
7
227 Views
Last Modified: 2010-03-31
I am executing a insert query from my java Program. In the insert query i am passing 0
as the value for one of the fields. In the Database side that value is replaced by a unique id
( some trigger and Sequence is used for that). To get that generated id i am again doing
another query. Is there any way by which i can avoid the 2nd query and can get the generated id from the first query itself ?
0
Comment
Question by:ugarg
  • 2
  • 2
7 Comments
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 9690784
No an insert cannot return a result set.
0
 
LVL 92

Expert Comment

by:objects
ID: 9690794
If available you could use a stored procedure to perform the insert and it could return the result.
0
 
LVL 15

Expert Comment

by:Javatm
ID: 9690910
Think there's no other way than this or what object said :

String query =  "INSERT INTO Tablename (VALUES) SELECT Values FROM YourDataBase";

Hope this helps . . .
JAVATM
0
 
LVL 15

Expert Comment

by:Javatm
ID: 9690936
Opps should be :

String query = "INSERT INTO Tablename (VALUES) SELECT Values FROM Tablename";
0
 
LVL 3

Expert Comment

by:evedder
ID: 9691196
String query= "Insert into tablename(id, field2, field3...fieldn)(select sequence.nextval, fieldfromtable1, fieldfromtable2, fieldfromtable3...fieldfromtablen from othertablename
)";

if you get only the id value from database

String query="Insert into tablename(id, field2, field3...fieldn)(select sequence.nextval,"+var1+","+var2+","+var3+...+varnblen+" from dual)";

where var2, var2, var3 are values defined in your application


salu2!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question