0
try
{
   Statement  stmt=con1.createStatement();
   String multiqueryString="Update table1 set name='';Select * fromaww table1; "

   boolean hasMoreResultSets = stmt.execute( multiQuerySqlString );
}

As you can see first statement is correct, but the second is incorrect (near from). But an update will be executed then Java will find error in second statement and give me error instead of separately telling about what happened to each statement.

How can I get update message and error message separately?

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
Rahul Choubey
  • 29
  • 1
  • 10
  • 2
    You stop executing several SQL queries at once. As far as I know, only MySQL allows that anyway (if MySQL can choose to do something stupid, it generally will). – JB Nizet Mar 04 '18 at 17:45
  • but I am taking sql queries as input from textarea I have to take multiple queries. – Rahul Choubey Mar 04 '18 at 17:46
  • Is there any way to do that?? @JB Nizet – Rahul Choubey Mar 04 '18 at 17:47
  • 2
    Search for allowMultiQueries in https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-configuration-properties.html. Notice that by default, it's false. Which is a good thing, since that is normally not supported by JDBC, and a really bad idea. So, either tell your users that only a single query is allowed, or split the entered text into multiple queries (but that isn't such an easy task without a SQL parser). – JB Nizet Mar 04 '18 at 17:51
  • How can I bulid a SQL Parser ?? Or should I separate the sql statements (like by semicolon ).But that would be problematic when delimiter is changed in making trigger?? @JBNizet – Rahul Choubey Mar 04 '18 at 17:56
  • please help @JBNizet Sir . Nobody is even able to understand this – Rahul Choubey Mar 04 '18 at 18:05
  • 2
    I told you: either let the driver throw an exception when the user tries entering several queries (which it should do), or write or find a SQL parser that allows splitting the entered text into multiple queries, and execute each query separately. – JB Nizet Mar 04 '18 at 18:07
  • @JBNizet Thank you very much Sir you made my day :) – Rahul Choubey Mar 04 '18 at 18:10

0 Answers0