SQLite中的update语句问题

Mar*_*ara 2 java sqlite

我使用SQLite创建了一个数据库.我想更新"功能"列的值(类型Blob)...但我不知道如何编写"更新"语句.这是我试过的:

    try {
        stat = conn.createStatement();
    } catch (SQLException e) {
    }
    try {
        byte[] b = getFunction();
        stat.executeUpdate("update table set features="+b);
    } catch (SQLException e) {
    }
Run Code Online (Sandbox Code Playgroud)

我得到了以下错误:

java.sql.SQLException: unrecognized token: "[B@13a317a"
Run Code Online (Sandbox Code Playgroud)

所以我猜"b"是问题?

Tho*_*ung 5

[B @ 13a317a看起来像一个数组到字符串结果(在这种情况下是b.toString()).您应该为blob使用准备好的语句,如:

update table set features=?
Run Code Online (Sandbox Code Playgroud)

一个例子是在这里.

通常,您不应该通过连接字符串来创建SQL.这是SQL注入问题的秘诀.