This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes generating tables by a variable name? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "generating tables by a variable name?" Watch "generating tables by a variable name?" New topic
Author

generating tables by a variable name?

sahar sa
Ranch Hand

Joined: Jul 06, 2009
Posts: 102
Dear friends,
I have a function that returns me a random number, which this random number is actually the number of tables I need to generate late on.(e.g: if random number is:3 we will have tables called T1,T2,T3 or if random number is: 30 we will have T1,T2,...,T30 ).My problem is How can I do this?
1) how can I generate a table when I dont know the actual name of my table?
I dont know if even is this possible?
if it's not do you have any idea how can I generate my tables or any other way I can solve this problem?

Thanks in advanced,
Sahar.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

But you do know the names of the tables you want to generate. You said:
if random number is:3 we will have tables called T1,T2,T3 or if random number is: 30 we will have T1,T2,...,T30

So do you have a problem generating a table whose name is T1? If so, what exactly is that problem?
R Bng
Greenhorn

Joined: Dec 29, 2006
Posts: 1
Sahar,

This should be possible. A couple of things to keep in mind, though -
1. You need to use a userid to connect to the DB that has appropriate permissions to run DDL commands
2. Introspect on the need to create tables. Can this be avoided?

You will have to generate strings with the names you want and run DDL commands using a prepared statement.
 
Consider Paul's rocket mass heater.
 
subject: generating tables by a variable name?
 
Similar Threads
Deadlocks in Threads?
hibernate Criteria "fast" search
sql syntax question
MySql Random Alphanumeric number
Help in writing a better program for Vampire numbers