我正在尝试通过以下方式在我的 Java 应用程序中使用 HyperSQL:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class Main {
static Connection conn;
static Statement stat;
public static void main(String[] args) {
try {
Class.forName("org.hsqldb.jdbc.JDBCDriver" );
} catch (Exception ex) {
System.out.println("An error occurred while loading HSQLDB JDBC driver: " + ex.getMessage());
return;
}
try {
conn = DriverManager.getConnection(
"jdbc:hsqldb:file:helper_db;sql.syntax_mys=true");
stat = conn.createStatement();
stat.executeUpdate(
"CREATE TABLE IF NOT EXISTS some_table " +
"(" +
"foo TEXT PRIMARY KEY, " +
"bar TEXT" +
");"
);
stat.executeUpdate(
"INSERT INTO some_table VALUES" +
"('foo', 'bar') " +
"ON DUPLICATE KEY UPDATE some_table = VALUES" +
"('foo', 'bar');"
);
} catch (Exception ex) {
System.out.println("An error occurred: " + ex.getMessage());
return;
}
}
}
这段代码给了我以下输出:
An error occurred: unexpected token: ON
我究竟做错了什么?如何解决这个问题?