This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Specifying Table Name Dynamically in Insert Statement.... 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 "Specifying Table Name Dynamically in Insert Statement...." Watch "Specifying Table Name Dynamically in Insert Statement...." New topic
Author

Specifying Table Name Dynamically in Insert Statement....

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
Can i specify table name dynamically in insert statement ? as follows...



Jigar Naik


Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3703
    
    5

Yeah, why wouldn't you be able to? For the most part, JDBC does not validate or even understand the SQL you send to the database server other than its just a SQL String.


My Blog: Down Home Country Coding with Scott Selikoff
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

Jigar,
Yes, you can build a Statement's SQL through String concatenation.

Note that you cannot write "insert into table ? ..." in a PreparedStatement though.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

Originally posted by Scott Selikoff:
JDBC does not validate or even understand the SQL you send to the database server other than its just a SQL String.


Nice clarification Scott,
I really appreciated your knowledge..


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
 
Don't get me started about those stupid light bulbs.
 
subject: Specifying Table Name Dynamically in Insert Statement....
 
Similar Threads
How to Insert data into MS Access?
Inserting multiple record into a database
Column count doesn't match value count at row 1
java.sql.SQLException: Invalid column index
insert statement