java - How to execute query of multiple statements as one? -
i came around obstacle . following statement not execute because string query
contains multiple statements .
string query="create volatile table test1 (etc . ); select top 10 * test1; "; string driver = "com.xxx"; string conurl="jdbc:ccc"; class.forname(driver); connection conn = drivermanager.getconnection(conurl,user,password); preparedstatement stmt=conn.preparestatement(query);
the last line throws error data definition not valid unless solitary
it cumbersome split query multiple preparedstatements
is there other way execute query containing multiple statements 1 ?
you use jdbc batch processing (addbatch, executebatch), allows "stack" statements , send them db engine executed @ once.
here starting point: http://viralpatel.net/blogs/batch-insert-in-java-jdbc/
but still need split separate statements, , add them 1 @ time. java: splitting comma-separated string ignoring commas in quotes
and, @cheburashka has pointed out, returns number of rows affected each statement - no if want ask actual data tables.
Comments
Post a Comment