我繞過障礙。以下語句不執行,因爲String query
包含多個語句。如何執行多個語句的查詢爲一個?
String query="create volatile table test1 as (etc .); select TOP 10 * from test1; ";
String driver = "com.xxx";
String conUrl="jdbc:ccc";
Class.forName(driver);
Connection conn = DriverManager.getConnection(conUrl,user,password);
PreparedStatement stmt=conn.prepareStatement(query);
最後一行拋出一個錯誤Data definition not valid unless solitary
這是非常麻煩我的查詢拆分成多個PreparedStatements
是否有執行包含多個語句作爲一個查詢任何其他方式?
哪些錯誤與獨立執行的呢? – David
如果用戶輸入查詢'create ... where x ='good; 「還有......」;選擇...。'我怎麼能確定的是,第一個查詢不字之後結束'good'我需要編寫額外的複雜的正則表達式 –
你可以試試'conn.createStatement()。對於試圖執行(SQL)'這有時會接受多個語句。但在一般情況下,如果使用JDBC,你需要知道在哪裏語句開始和結束。 – vanOekel