0

I have a Java servlet that connects to a MySQL database. And it is possible to create new tables under runtime, which means I do not know what their names are.

So here is the problem; I want to be able to find a value in the unknown table, and compare it to another in a table I have the name of.. I'm not sure where to go, or if this is even possible.

SHOW TABLES IN database_name;

Returns all the tables I want to use.

Appreciate any help.

1
  • You should not allow access to the SHOW TABLES command from a Servlet. This may jeopardize your application. Commented Dec 16, 2010 at 21:32

3 Answers 3

2

You can use the getTables() function on a DatabaseMetaData object to get the names of the tables in the database. It takes a tableNamePattern argument.

Sign up to request clarification or add additional context in comments.

Comments

1

You need to know something about the table. If you don't know the name, you need to know something about it to determine what its name is. This determines what you must do to lookup the name. i.e. you need to be more specific about what you know about the table.

Comments

0

Sounds like you're trying to re-implement database CRUD from scratch. Most good web frameworks already do this quite well. Try learning Grails.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.