Creates a database cursor.
PSConnectionClass objects
connectionobject.CreateCursor( sql )
Syntax with multiple arguments
connectionobject.CreateCursor( sql , resultSetType, resultSetConcurrency )
Argument |
Description |
---|---|
connectionobject |
A variable that contains a reference to an instance of PSConnectionClass. |
sql |
A string that specifies the SQL statement. |
resultSetType |
An int that specifies the result set type. If the single argument syntax is used in a JSP target, TYPE_SCROLL_INSENSITIVE is passed as a default argument. |
resultSetConcurrency |
An int that specifies the result set concurrency properties. If the single argument syntax is used in a JSP target, CONCUR_UPDATABLE is passed as a default argument. |
PSCursorClass object
At runtime, CreateCursor creates a cursor object and executes the SQL statement.
The following example creates a cursor to retrieve rows from the products table. Once the data has been retrieved, the code in the example writes out each row in the cursor. If an error occurs, it writes out the error code and message text:
String myquery;
PSConnectionClass myconnect;
PSCursorClass mycursor;
PSErrorClass errobj;
boolean dberror;
myConnect = psServer.CreateConnection(pageContext, "com.sybase.jdbc2.jdbc.SybDriver", "jdbc:sybase:Tds:localhost:2638", "dba", "sql", true);
...
myquery = "SELECT products.prod_id, products.prod_name FROM DBA.products";
mycursor = myconnect.CreateCursor(myquery);
if ( myconnect.GetError() == null )
{
for (i=0; (!mycursor.EOF()); i++)
{
psDocument.Write(mycursor.GetValue(0) + " " + mycursor.GetValue(1));
psDocument.Write("<BR>");
mycursor.MoveNext();
}
}
else {
dberror = true;
}
if ( dberror == true )
{
errobj = myconnect.GetError();
str = errobj.GetCode() + " " + errobj.GetMessage();
psDocument.Write ( str );
}