createQuery()

You can open a database cursor for an SQL query by using the Database.createQuery() function. Once the cursor is open, you can retrieve large result sets from the database in pages.

Syntax

String createQuery(String jdbcURI, String cursorName, String resultTypeURI, String sql, int pageSize, Object requestObj);

Parameters

Parameter Type Description
jdbcURI String The JDBC URI of the resource to be used for getting the connection.
cursorName String The name of the cursor to be opened.
resultTypeURI String The URI of the result type, which will be returned by the query. Possible values are Concept URI, Map, or Null. If it is of "Map" type, then each result set row is a Map object. In this case, you can retrieve the column values by specifying column names as the key. If Null, an Object[] is returned.
sql String The SQL query string. It can be a prepared statement query or a simple statement query.
pageSize Integer The number of concepts or records to be fetched from the database for each page.
requestObj Object If the SQL query specified is a prepared statement query, then the requestObject can be specified as a concept or an array of arguments.
returns String The name of the opened cursor.

Example

Database.setCurrentConnection("/SharedResources/Oracle.sharedjdbc");
String jdbcURI="/SharedResources/HR_DB_Conn.sharedjdbc";
String cursorName="EmpCursor";
String resultTypeURI="/Concepts/HR/EMPLOYEES";
String sql="select * from employees";
int pageSize=10;
Object requestObj=null;
String cursorName=Database.createQuery(jdbcURI,cursorName,resultTypeURI,sql,pageSize,requestObj);
System.debugOut(" Opened Cursor: " + cursorName);