Reputation: 62732
Specifically, I run these statements:
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);
I was wondering whether it is possible to do it with one execute command? What I tried is simply concat the two strings and execute. But hsqldb complains that the table on which an index is being created does not exist.
Upvotes: 0
Views: 301
Reputation: 159754
The docs for HSQLDB don't offer any way of specifying a table index during table creation, therefore you will have to make 2 individual calls to the database.
As an aside, I would recommend to use PreparedStatement
to protect again SQL injection attacks. The use of placeholders eliminate the need to use String.format
.
Upvotes: 1