开发者

JDBC general query execution

Is there a way, in JDBC, to execute a generic query ? I mean run something like execute(String strSql) where strSql could be a SELECT, an INSERT, an UPDATE,a CREATE,... or whatever.

If no, how would you fix this up ?

Proposed solution:

@Override
public void execQuery(String Query) throws SQLException {
    this.statement = this.connection.createStatement();
    if (this.statement.execute(Query)) {
        t开发者_如何学JAVAhis.resultset = this.statement.getResultSet();
    }
}


Note that your proposed solution is susceptible a SQL injection attack. Use java.sql.PreparedStatement instead, as described in Using Prepared Statements.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜