• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with PreparedStatement

 
Elihu Smails
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic