Share via


IConnection.PrepareStatement Method

Definition

Overloads

PrepareStatement(String)

Creates a PreparedStatement object for sending parameterized SQL statements to the database.

PrepareStatement(String, Int32)

Creates a default PreparedStatement object that has the capability to retrieve auto-generated keys.

PrepareStatement(String, Int32[])

Creates a default PreparedStatement object capable of returning the auto-generated keys designated by the given array.

PrepareStatement(String, String[])

Creates a default PreparedStatement object capable of returning the auto-generated keys designated by the given array.

PrepareStatement(String, Int32, Int32)

Creates a PreparedStatement object that will generate ResultSet objects with the given type and concurrency.

PrepareStatement(String, Int32, Int32, Int32)

Creates a PreparedStatement object that will generate ResultSet objects with the given type, concurrency, and holdability.

PrepareStatement(String)

Creates a PreparedStatement object for sending parameterized SQL statements to the database.

[Android.Runtime.Register("prepareStatement", "(Ljava/lang/String;)Ljava/sql/PreparedStatement;", "GetPrepareStatement_Ljava_lang_String_Handler:Java.Sql.IConnectionInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public Java.Sql.IPreparedStatement? PrepareStatement (string? sql);
[<Android.Runtime.Register("prepareStatement", "(Ljava/lang/String;)Ljava/sql/PreparedStatement;", "GetPrepareStatement_Ljava_lang_String_Handler:Java.Sql.IConnectionInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member PrepareStatement : string -> Java.Sql.IPreparedStatement

Parameters

sql
String

an SQL statement that may contain one or more '?' IN parameter placeholders

Returns

a new default PreparedStatement object containing the pre-compiled SQL statement

Attributes

Exceptions

if there is a problem accessing the database.

Remarks

Creates a PreparedStatement object for sending parameterized SQL statements to the database.

A SQL statement with or without IN parameters can be pre-compiled and stored in a PreparedStatement object. This object can then be used to efficiently execute this statement multiple times.

<B>Note:</B> This method is optimized for handling parametric SQL statements that benefit from precompilation. If the driver supports precompilation, the method prepareStatement will send the statement to the database for precompilation. Some drivers may not support precompilation. In this case, the statement may not be sent to the database until the PreparedStatement object is executed. This has no direct effect on users; however, it does affect which methods throw certain SQLException objects.

Result sets created using the returned PreparedStatement object will by default be type TYPE_FORWARD_ONLY and have a concurrency level of CONCUR_READ_ONLY. The holdability of the created result sets can be determined by calling #getHoldability.

Java documentation for java.sql.Connection.prepareStatement(java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

PrepareStatement(String, Int32)

Creates a default PreparedStatement object that has the capability to retrieve auto-generated keys.

[Android.Runtime.Register("prepareStatement", "(Ljava/lang/String;I)Ljava/sql/PreparedStatement;", "GetPrepareStatement_Ljava_lang_String_IHandler:Java.Sql.IConnectionInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public Java.Sql.IPreparedStatement? PrepareStatement (string? sql, int autoGeneratedKeys);
[<Android.Runtime.Register("prepareStatement", "(Ljava/lang/String;I)Ljava/sql/PreparedStatement;", "GetPrepareStatement_Ljava_lang_String_IHandler:Java.Sql.IConnectionInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member PrepareStatement : string * int -> Java.Sql.IPreparedStatement

Parameters

sql
String

an SQL statement that may contain one or more '?' IN parameter placeholders

autoGeneratedKeys
Int32

a flag indicating whether auto-generated keys should be returned; one of Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS

Returns

a new PreparedStatement object, containing the pre-compiled SQL statement, that will have the capability of returning auto-generated keys

Attributes

Exceptions

if there is a problem accessing the database.

Remarks

Creates a default PreparedStatement object that has the capability to retrieve auto-generated keys. The given constant tells the driver whether it should make auto-generated keys available for retrieval. This parameter is ignored if the SQL statement is not an INSERT statement, or an SQL statement able to return auto-generated keys (the list of such statements is vendor-specific).

<B>Note:</B> This method is optimized for handling parametric SQL statements that benefit from precompilation. If the driver supports precompilation, the method prepareStatement will send the statement to the database for precompilation. Some drivers may not support precompilation. In this case, the statement may not be sent to the database until the PreparedStatement object is executed. This has no direct effect on users; however, it does affect which methods throw certain SQLExceptions.

Result sets created using the returned PreparedStatement object will by default be type TYPE_FORWARD_ONLY and have a concurrency level of CONCUR_READ_ONLY. The holdability of the created result sets can be determined by calling #getHoldability.

Added in 1.4.

Java documentation for java.sql.Connection.prepareStatement(java.lang.String, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

PrepareStatement(String, Int32[])

Creates a default PreparedStatement object capable of returning the auto-generated keys designated by the given array.

[Android.Runtime.Register("prepareStatement", "(Ljava/lang/String;[I)Ljava/sql/PreparedStatement;", "GetPrepareStatement_Ljava_lang_String_arrayIHandler:Java.Sql.IConnectionInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public Java.Sql.IPreparedStatement? PrepareStatement (string? sql, int[]? columnIndexes);
[<Android.Runtime.Register("prepareStatement", "(Ljava/lang/String;[I)Ljava/sql/PreparedStatement;", "GetPrepareStatement_Ljava_lang_String_arrayIHandler:Java.Sql.IConnectionInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member PrepareStatement : string * int[] -> Java.Sql.IPreparedStatement

Parameters

sql
String

an SQL statement that may contain one or more '?' IN parameter placeholders

columnIndexes
Int32[]

an array of column indexes indicating the columns that should be returned from the inserted row or rows

Returns

a new PreparedStatement object, containing the pre-compiled statement, that is capable of returning the auto-generated keys designated by the given array of column indexes

Attributes

Exceptions

if a problem occurs accessing the database.

Remarks

Creates a default PreparedStatement object capable of returning the auto-generated keys designated by the given array. This array contains the indexes of the columns in the target table that contain the auto-generated keys that should be made available. The driver will ignore the array if the SQL statement is not an INSERT statement, or an SQL statement able to return auto-generated keys (the list of such statements is vendor-specific).

An SQL statement with or without IN parameters can be pre-compiled and stored in a PreparedStatement object. This object can then be used to efficiently execute this statement multiple times.

<B>Note:</B> This method is optimized for handling parametric SQL statements that benefit from precompilation. If the driver supports precompilation, the method prepareStatement will send the statement to the database for precompilation. Some drivers may not support precompilation. In this case, the statement may not be sent to the database until the PreparedStatement object is executed. This has no direct effect on users; however, it does affect which methods throw certain SQLExceptions.

Result sets created using the returned PreparedStatement object will by default be type TYPE_FORWARD_ONLY and have a concurrency level of CONCUR_READ_ONLY. The holdability of the created result sets can be determined by calling #getHoldability.

Added in 1.4.

Java documentation for java.sql.Connection.prepareStatement(java.lang.String, int[]).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

PrepareStatement(String, String[])

Creates a default PreparedStatement object capable of returning the auto-generated keys designated by the given array.

[Android.Runtime.Register("prepareStatement", "(Ljava/lang/String;[Ljava/lang/String;)Ljava/sql/PreparedStatement;", "GetPrepareStatement_Ljava_lang_String_arrayLjava_lang_String_Handler:Java.Sql.IConnectionInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public Java.Sql.IPreparedStatement? PrepareStatement (string? sql, string[]? columnNames);
[<Android.Runtime.Register("prepareStatement", "(Ljava/lang/String;[Ljava/lang/String;)Ljava/sql/PreparedStatement;", "GetPrepareStatement_Ljava_lang_String_arrayLjava_lang_String_Handler:Java.Sql.IConnectionInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member PrepareStatement : string * string[] -> Java.Sql.IPreparedStatement

Parameters

sql
String

an SQL statement that may contain one or more '?' IN parameter placeholders

columnNames
String[]

an array of column names indicating the columns that should be returned from the inserted row or rows

Returns

a new PreparedStatement object, containing the pre-compiled statement, that is capable of returning the auto-generated keys designated by the given array of column names

Attributes

Exceptions

if a problem occurs accessing the database.

Remarks

Creates a default PreparedStatement object capable of returning the auto-generated keys designated by the given array. This array contains the names of the columns in the target table that contain the auto-generated keys that should be returned. The driver will ignore the array if the SQL statement is not an INSERT statement, or an SQL statement able to return auto-generated keys (the list of such statements is vendor-specific).

An SQL statement with or without IN parameters can be pre-compiled and stored in a PreparedStatement object. This object can then be used to efficiently execute this statement multiple times.

<B>Note:</B> This method is optimized for handling parametric SQL statements that benefit from precompilation. If the driver supports precompilation, the method prepareStatement will send the statement to the database for precompilation. Some drivers may not support precompilation. In this case, the statement may not be sent to the database until the PreparedStatement object is executed. This has no direct effect on users; however, it does affect which methods throw certain SQLExceptions.

Result sets created using the returned PreparedStatement object will by default be type TYPE_FORWARD_ONLY and have a concurrency level of CONCUR_READ_ONLY. The holdability of the created result sets can be determined by calling #getHoldability.

Added in 1.4.

Java documentation for java.sql.Connection.prepareStatement(java.lang.String, java.lang.String[]).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

PrepareStatement(String, Int32, Int32)

Creates a PreparedStatement object that will generate ResultSet objects with the given type and concurrency.

[Android.Runtime.Register("prepareStatement", "(Ljava/lang/String;II)Ljava/sql/PreparedStatement;", "GetPrepareStatement_Ljava_lang_String_IIHandler:Java.Sql.IConnectionInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public Java.Sql.IPreparedStatement? PrepareStatement (string? sql, int resultSetType, int resultSetConcurrency);
[<Android.Runtime.Register("prepareStatement", "(Ljava/lang/String;II)Ljava/sql/PreparedStatement;", "GetPrepareStatement_Ljava_lang_String_IIHandler:Java.Sql.IConnectionInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member PrepareStatement : string * int * int -> Java.Sql.IPreparedStatement

Parameters

sql
String

a String object that is the SQL statement to be sent to the database; may contain one or more '?' IN parameters

resultSetType
Int32

a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE

resultSetConcurrency
Int32

a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE

Returns

a new PreparedStatement object containing the pre-compiled SQL statement that will produce ResultSet objects with the given type and concurrency

Attributes

Exceptions

if a problem occurs accessing the database.

Remarks

Creates a PreparedStatement object that will generate ResultSet objects with the given type and concurrency. This method is the same as the prepareStatement method above, but it allows the default result set type and concurrency to be overridden. The holdability of the created result sets can be determined by calling #getHoldability.

Added in 1.2.

Java documentation for java.sql.Connection.prepareStatement(java.lang.String, int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

PrepareStatement(String, Int32, Int32, Int32)

Creates a PreparedStatement object that will generate ResultSet objects with the given type, concurrency, and holdability.

[Android.Runtime.Register("prepareStatement", "(Ljava/lang/String;III)Ljava/sql/PreparedStatement;", "GetPrepareStatement_Ljava_lang_String_IIIHandler:Java.Sql.IConnectionInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public Java.Sql.IPreparedStatement? PrepareStatement (string? sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability);
[<Android.Runtime.Register("prepareStatement", "(Ljava/lang/String;III)Ljava/sql/PreparedStatement;", "GetPrepareStatement_Ljava_lang_String_IIIHandler:Java.Sql.IConnectionInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member PrepareStatement : string * int * int * int -> Java.Sql.IPreparedStatement

Parameters

sql
String

a String object that is the SQL statement to be sent to the database; may contain one or more '?' IN parameters

resultSetType
Int32

one of the following ResultSet constants: ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE

resultSetConcurrency
Int32

one of the following ResultSet constants: ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE

resultSetHoldability
Int32

one of the following ResultSet constants: ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT

Returns

a new PreparedStatement object, containing the pre-compiled SQL statement, that will generate ResultSet objects with the given type, concurrency, and holdability

Attributes

Exceptions

if a problem occurs accessing the database.

Remarks

Creates a PreparedStatement object that will generate ResultSet objects with the given type, concurrency, and holdability.

This method is the same as the prepareStatement method above, but it allows the default result set type, concurrency, and holdability to be overridden.

Added in 1.4.

Java documentation for java.sql.Connection.prepareStatement(java.lang.String, int, int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to