Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

generating tables by a variable name?

 
sahar sa
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic