1
我有包含bytea
列的PostgreSQL表。例如:PostgreSQL JDBC PreparedStatement的setBytes更改參數值
CREATE TABLE my_table (
text_col text NOT NULL,
bytea_col bytea NOT NULL
);
插入到表中使用PreparedStatement
是這樣的:
...
byte[] value = "ABC".getBytes();
String insertStmt = "INSERT INTO my_table (text_col, bytea_col) VALUES (?, ?)";
PreparedStatement ps = conn.prepareStatement(insertStmt);
ps.setString(1, "SomeString");
ps.setBytes(2, value);
...
當對於字符串ABC
字節[]被印刷,它是:[65 66 67]
。 但是,當我查看數據庫中的插入值時,它是:\x414243
,我假設它等於[41 42 43]
的一個字節[]。
因此,當我在我的WHERE子句中使用[65 66 67]
進行查詢時,該行永遠找不到。
select * from my_table where bytes_col = E'\\x656667';
是否在PreparedStatement
變化setBytes
我傳遞中的字節?這似乎是錯誤的。我做錯了什麼嗎?