2013-03-23 57 views
0

具體來說,我運行這些語句:是否可以使用JDBC接口對hsqldb執行多個sql語句?

String script = String.format(
     "CREATE CACHED TABLE IF NOT EXISTS %s (id VARCHAR(36), value %s, PRIMARY KEY (id));", indexName, getIndexType()); 
    st.execute(script); 
    script = String.format("CREATE INDEX idx_%s ON %s (value);", indexName, indexName); 
    st.execute(script); 

我想知道是否有可能與一個做執行命令?我所嘗試的只是將這兩個字符串連接起來並執行。但hsqldb抱怨索引正在創建的表不存在。

回答

1

HSQLDB的docs在創建表時不提供任何指定表索引的方法,因此您必須對數據庫進行2次單獨調用。

另外,我建議使用PreparedStatement來保護SQL注入攻擊。佔位符的使用消除了使用String.format的需要。

相關問題