execute SQL statements directly

逻辑代码块需要放在Class的server static 修饰的method里。
不能直接把代码块放在Job里执行。

server static void main(Args _args)
{
    UserConnection userConnection;
    Statement statement;
    SqlSystem sqlSystem;
    
    str sqlStatement;
    SqlStatementExecutePermission sqlPermission;
    ResultSet resultSet;
    
    sqlStatement = 'SELECT CustGroup,Name,dataAreaId FROM CustGroup';
    
    userConnection = new UserConnection();
    statement = userConnection.createStatement();
    sqlPermission = new SqlStatementExecutePermission(sqlStatement);
    
    sqlPermission.assert();
    resultSet = statement.executeQuery(sqlStatement);
    CodeAccessPermission::revertAssert();
    
    while (resultSet.next())
    {
        info(strFmt(
            "%1 - %2 - %3",
            resultSet.getString(1),
            resultSet.getString(2),
            resultSet.getString(3)));
    }
}

你可能感兴趣的:(execute SQL statements directly)