0

i have a code input array like this the variable name is "output" Assume that variable "output" is a list of a Column_Name in Array. the real output i want to get is the list of Table_name and Column_Name that i will show in the Jtable that i have set. the main of things to do is how to execute those Query using all of the "output" values so i can get every Table_Name of its

String[] output= example.split(",");

after i got an Array list i want to execute one by one of the Array value to a SQL statement and the processing code is like this

for (String outputInsert : output) {
    try {
        rs2 = stmt.executeQuery("SELECT TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA ='"+sqldb+ "' AND COLUMN_NAME = '"+outputInsert+"';");           
    } catch (SQLException ex) {
        Logger.getLogger(Retrieve.class.getName()).log(Level.SEVERE, null, ex);
    }
} result rs2;

but i didn't get the result that i want that show all the value of every executed SQL statement

2
  • Can you be more specific on what output you do get and what does your logger show? Also it would be nice if for that case show the input too, I suspect the problem is in typos/quotemarks. Commented May 14, 2017 at 5:00
  • what does result rs2; and the end ?! Commented May 14, 2017 at 5:03

2 Answers 2

0

You need to use addBatch and executeBatch commands instead of executeQuery. Please refer to this post Execute multiple SQL statements in java.

stmt.addBatch(query1);
stmt.addBatch(query2);

stmt.executeBatch();
Sign up to request clarification or add additional context in comments.

Comments

-1

If there is a list of value for a given column value , instead of hitting data base for every value,please try with IN clause in sql query. NOTE: There is a limitation maximum value can pass in IN clause.

4 Comments

that does not address the question - its not about efficiency, and I doubt it would improve in this case critically
I thought how to pass array value to a select query if that is not the case ,then can you please clarify
read the question itself, not the title. She doesn't get valid rs2 all the time.
may be it's not answering how to execute the Array list but it give me a new perspective for Using IN for my Query. thankyou so much i will try this

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.