Skip to content
Advertisement

Is it possible to search all tables in MySQL workbench database with java preparedstatement SQL in order to change a value?

I have several tables like this in a Schema/Database (the Schema is called “user”) in MySQL workbench:

JavaScript

Suppose Sarah gets a score change to 5. I want to update all of her scores in all of the tables in which she exists, to be 5. So then the 3 tables would look like this:

JavaScript

Is this possible to do using a java prepared SQL statement? If so, how would I do it? Thanks in advance. I can’t seem to find anything on this. One way I know would work is searching for each table, putting the table names in an arraylist and then searching each one in a loop. But I’m not sure that’s the best approach for this.

I was thinking something like this, if it were possible (some awkward psuedo-code):

JavaScript

Advertisement

Answer

It looks like you need to build your statement dynamically like this:

JavaScript

output can be something like this:

JavaScript

How to Execute Dynamic Sql String as a Query in mysql server? was asked before …

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement