aspose file tools*
The moose likes JDBC and the fly likes Insert Query using select statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Insert Query using select statement" Watch "Insert Query using select statement" New topic
Author

Insert Query using select statement

Skanda Raman
Ranch Hand

Joined: Mar 21, 2008
Posts: 205

Actually i have a requirement to insert into table by selecting two columns from other table and one hard coded value is given in the query.


Here i want firstname and lastname from user table into tstore table and just id is different and hence i have hardcoded as 219 (i will loop this count so that i get different number each time using java).

Initially before putting the code to java, my sql console gives me the error as syntax error.

I am using oracle10g database.

please let me know if am doing wrong


Skanda
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3860

See weather INSERT INTO... SELECT helps. Syntax may be the same for Oracle too.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Skanda Raman
Ranch Hand

Joined: Mar 21, 2008
Posts: 205

Thanks. The link was great.

But here i have two values to be inserted from the select statement and only one value to be given from me. Some thing like this.

insert into tstore (firstname,lastname,id)
(select firstname,lastname from user where userid='eshwar'),219

The firstname and lastname to be inserted comes from select statement and id is the number i am giving.

This gives me an error
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3860

Eshwar Prasad wrote:insert into tstore (firstname,lastname,id)
(select firstname,lastname from user where userid='eshwar'),219

Is this work ?
Skanda Raman
Ranch Hand

Joined: Mar 21, 2008
Posts: 205


Many Thanks. It worked.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Insert Query using select statement