Solved

Can i get any result back from the insert Query?

Posted on 2003-11-05
7
201 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now