aspose file tools
The moose likes JDBC and the fly likes Help with PreparedStatement Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Help with PreparedStatement" Watch "Help with PreparedStatement" New topic
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
    
  66

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with PreparedStatement
 
Similar Threads
Dynamic SQL Query Doubt
Primary Key. Auto update or manual update?
JDBC issue with Oracle LONG datatype
Question about SQL select - Performance
Relative query efficiencies