• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Help with PreparedStatement

 
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.
 
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.
 
author & internet detective
Posts: 39343
755
Eclipse IDE VI Editor Java
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!