Meaningless Drivel is fun!*
The moose likes JDBC and the fly likes how can we use where clause with insert query using preparedStatement? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how can we use where clause with insert query using preparedStatement?" Watch "how can we use where clause with insert query using preparedStatement?" New topic
Author

how can we use where clause with insert query using preparedStatement?

Rd Dari
Ranch Hand

Joined: Feb 22, 2010
Posts: 206

Hi everyone,


I want to insert value from a table into anoother how it is possible to insert with where caluse


my query is below:



and I want in this----

cat is the dynamic.........

thank you.
Sudheer Bhat
Ranch Hand

Joined: Feb 22, 2011
Posts: 75
Your insert statement should look like

Insert into tab1(column list) SELECT val1, val2,........ FROM tab2 WHERE ........... ;
Make sure your SELECT returns correct data types for the tab1 in the same order as column list.
Rd Dari
Ranch Hand

Joined: Feb 22, 2010
Posts: 206

what is in this ......




out put is here ;;;;


I tried a lot but not done

please correct this syntax error
Sudheer Bhat
Ranch Hand

Joined: Feb 22, 2011
Posts: 75
Your SQL query should look like Insert into tab1(column list) SELECT val1, val2,........ FROM tab2 WHERE ........... ;
Rd Dari
Ranch Hand

Joined: Feb 22, 2010
Posts: 206

but as I need some field extra in history_grocery and some missing from grocery

it this case what i should do???

like..


and

some values are come using ajax and js in view(jsp page)like quantity and total_amount....
Sudheer Bhat
Ranch Hand

Joined: Feb 22, 2011
Posts: 75
you can actually pass all the values which are coming from view to the SQL statement. If you need to select one field from another table and other 10 values coming from view then your SELECT part of INSERT statement would look like SELECT ?,?,?........., col1, col2 FROM table where ....
You would set the values which you retrieved from the view using statement.set... methods.
 
Consider Paul's rocket mass heater.
 
subject: how can we use where clause with insert query using preparedStatement?
 
Similar Threads
How to distinguish between two different button clicks on servlet
how do i insert more than one row to my table
how to retrieve value from autogenerated(oracle sequence) column in a servlet.
SQL Exception:General Error
How to insert value in a table using session(ArrayList)?