| Author |
Help with PreparedStatement
|
Elihu Smails
Ranch Hand
Joined: Jan 12, 2005
Posts: 37
|
|
My application generates table names based on a client identification. For instance, when I add a new client and assign a number, I generate tables basedo on the client ID. For instance, if I create a new client with ID=1234, then I will have a table "client123info". Now if I want to use a PreparedStatement, I cannot do the following: PreparedStatement ps = connection.prepareStatement( "select * from client?info"); because the SQL ends up looking like this: select * from client'1234'info So what can I do? Thanks.
|
 |
Michael Duffy
Ranch Hand
Joined: Oct 15, 2005
Posts: 163
|
|
Originally posted by Elihu Smails: My application generates table names based on a client identification. For instance, when I add a new client and assign a number, I generate tables basedo on the client ID. For instance, if I create a new client with ID=1234, then I will have a table "client123info". Now if I want to use a PreparedStatement, I cannot do the following: PreparedStatement ps = connection.prepareStatement( "select * from client?info"); because the SQL ends up looking like this: select * from client'1234'info So what can I do? Thanks.
|
%
|
 |
Michael Duffy
Ranch Hand
Joined: Oct 15, 2005
Posts: 163
|
|
Originally posted by Elihu Smails: My application generates table names based on a client identification. For instance, when I add a new client and assign a number, I generate tables basedo on the client ID. For instance, if I create a new client with ID=1234, then I will have a table "client123info". Now if I want to use a PreparedStatement, I cannot do the following: PreparedStatement ps = connection.prepareStatement( "select * from client?info"); because the SQL ends up looking like this: select * from client'1234'info So what can I do? Thanks.
I don't like this design at all. A table for each client instead of rows in a table? I'm not sure why you think you have to do this, but without additional knowledge I'd say it ought to be changed. This is not something you can do with PreparedStatement. It binds to variables, not names.
|
 |
Elihu Smails
Ranch Hand
Joined: Jan 12, 2005
Posts: 37
|
|
Each client will have monthly entries to be placed into the database. I just thought it made more sense to keep each clients' information separate. Plus is makes the SQL queries alot easier to deal with, since I am not that good with SQL. Do you have any other ideas, I would appreciate any more feedback.
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26201
|
|
Elihu, I agree with Michael. You need to have one table with a column for client id. Then you can do queries like: select columns from clientinfo where clientId = ? This is still a simple query. And this gives you a good opportunity to learn more about SQL! If you have questions about SQL, feel free to post them here. There are also some good references in the FAQ linked to at the top of this forum.
|
[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
|
 |
 |
|
|
subject: Help with PreparedStatement
|
|
|