我讀過關於在數據庫中存儲對象的H2文檔。有特殊的SQL類型OTHER和方法setObject
和getObject
。我試過這段代碼:如何將對象插入到h2
PreparedStatement statement = null;
try {
statement = connection.prepareStatement("CREATE TABLE PUBLIC.foo (name VARCHAR(64) NOT NULL, data OTHER NULL);");
statement.execute();
} finally {
statement.close();
}
statement = null;
try {
statement = connection.prepareStatement("INSERT INTO PUBLIC.foo (name, data) VALUES(?,?);");
statement.setString(1, "lololo");
statement.setObject(2, new String[]{"foo", "bar"});
statement.execute();
}finally {
statement.close();
}
但我有例外:
org.h2.jdbc.JdbcSQLException:ШÐμÑÑ,наÐ'цd° ÑõиричннÑÑÑÑÑÑÑÑÑÑмÐвоÐвÐнÐнÐнÐнÐннÐнÐнÐÐнÐÐÐнÐÑ 「(foo,bar)」 十六進制字符串包含非十六進制字符:「(foo,bar)」; SQL語句:(?) INSERT INTO PUBLIC.foo(名稱,數據)VALUES - (?1,2)[90004-191]
有什麼不對?
看看這裏:http://stackoverflow.com/questions/31964209/h2-other-data-type-throws-exception-when-storing -string-or-boolean – Seelenvirtuose
非常感謝。 –