小编dio*_*ogo的帖子

java - PSQLException:错误:“$1”处或附近的语法错误

我是否在PreparedStatement 中错误地使用了语法?

执行时:

1    statement = conn.prepareStatement("insert into ?.? (?) values(?)");
2    statement.setString(1, schemaName);
3    statement.setString(2, tableName);
4    statement.setString(3, columnName);
5    statement.setString(4, columnValue);
6    statement.executeUpdate();
7    conn.commit();
Run Code Online (Sandbox Code Playgroud)

抛出的异常:

org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"
Position: 13
    at  org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2477)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2190)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:300)
    at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)
    at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:169)
    at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:136)
    at PostgreSQLDatabase.updateTable(MyClass.java:6)
Run Code Online (Sandbox Code Playgroud)

postgresql jdbc prepared-statement

2
推荐指数
1
解决办法
7519
查看次数

标签 统计

jdbc ×1

postgresql ×1

prepared-statement ×1