Solved

Can i get any result back from the insert Query?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse formatting 6 71
Java / Linux and Regular Expressions 11 69
How to monitor the number of connections/threads being utilized on Tomcat 6.0 8 54
servlet example issue 6 29
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

912 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

18 Experts available now in Live!

Get 1:1 Help Now