Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Can i get any result back from the insert Query?

Posted on 2003-11-05
7
Medium Priority
?
244 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
7 Comments
 
LVL 92

Accepted Solution

by:
objects earned 1000 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

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…
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…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

705 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