# DatabaseUtils.InsertHelper

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in[API level 17](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# InsertHelper

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/database/DatabaseUtils.InsertHelper "View this page in Java")  

```
open class InsertHelper
```

|---|--------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                             ||
| ↳ | [android.database.DatabaseUtils.InsertHelper](https://developer.android.com/reference/kotlin/android/database/DatabaseUtils.InsertHelper#) |

*** ** * ** ***

| **This class was deprecated in API level 17.**
|
| Use[SQLiteStatement](https://developer.android.com/reference/kotlin/android/database/sqlite/SQLiteStatement)instead.

This class allows users to do multiple inserts into a table using the same statement.

This class is not thread-safe.

## Summary

|                                                                                                                                                                                               Public constructors                                                                                                                                                                                                ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [InsertHelper](https://developer.android.com/reference/kotlin/android/database/DatabaseUtils.InsertHelper#InsertHelper(android.database.sqlite.SQLiteDatabase,%20kotlin.String))`(`db:` `[SQLiteDatabase](https://developer.android.com/reference/kotlin/android/database/sqlite/SQLiteDatabase)!`, `tableName:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`)` <br /> |

|                                                                                                                                                                                                                   Public methods                                                                                                                                                                                                                    ||
|----------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [bind](https://developer.android.com/reference/kotlin/android/database/DatabaseUtils.InsertHelper#bind(kotlin.Int,%20kotlin.Boolean))`(`index:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `value:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` Bind the value to an index.         |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [bind](https://developer.android.com/reference/kotlin/android/database/DatabaseUtils.InsertHelper#bind(kotlin.Int,%20kotlin.ByteArray))`(`index:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `value:` `[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)!`)` Bind the value to an index. |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [bind](https://developer.android.com/reference/kotlin/android/database/DatabaseUtils.InsertHelper#bind(kotlin.Int,%20kotlin.Double))`(`index:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `value:` `[Double](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-double/index.html)`)` Bind the value to an index.            |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [bind](https://developer.android.com/reference/kotlin/android/database/DatabaseUtils.InsertHelper#bind(kotlin.Int,%20kotlin.Float))`(`index:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `value:` `[Float](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html)`)` Bind the value to an index.               |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [bind](https://developer.android.com/reference/kotlin/android/database/DatabaseUtils.InsertHelper#bind(kotlin.Int,%20kotlin.Int))`(`index:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `value:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Bind the value to an index.                     |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [bind](https://developer.android.com/reference/kotlin/android/database/DatabaseUtils.InsertHelper#bind(kotlin.Int,%20kotlin.String))`(`index:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `value:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`)` Bind the value to an index.           |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [bind](https://developer.android.com/reference/kotlin/android/database/DatabaseUtils.InsertHelper#bind(kotlin.Int,%20kotlin.Long))`(`index:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `value:` `[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`)` Bind the value to an index.                  |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [bindNull](https://developer.android.com/reference/kotlin/android/database/DatabaseUtils.InsertHelper#bindNull(kotlin.Int))`(`index:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Bind null to an index.                                                                                                                       |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [close](https://developer.android.com/reference/kotlin/android/database/DatabaseUtils.InsertHelper#close())`()` Close this object and release any resources associated with it.                                                                                                                                                                                   |
| open[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | [execute](https://developer.android.com/reference/kotlin/android/database/DatabaseUtils.InsertHelper#execute())`()` Execute the previously prepared insert or replace using the bound values since the last call to prepareForInsert or prepareForReplace.                                                                                                        |
| open[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)   | [getColumnIndex](https://developer.android.com/reference/kotlin/android/database/DatabaseUtils.InsertHelper#getColumnIndex(kotlin.String))`(`key:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`)` Returns the index of the specified column.                                                                               |
| open[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | [insert](https://developer.android.com/reference/kotlin/android/database/DatabaseUtils.InsertHelper#insert(android.content.ContentValues))`(`values:` `[ContentValues](https://developer.android.com/reference/kotlin/android/content/ContentValues.html#)!`)` Performs an insert, adding a new row with the given values.                                        |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [prepareForInsert](https://developer.android.com/reference/kotlin/android/database/DatabaseUtils.InsertHelper#prepareForInsert())`()` Prepare the InsertHelper for an insert.                                                                                                                                                                                     |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [prepareForReplace](https://developer.android.com/reference/kotlin/android/database/DatabaseUtils.InsertHelper#prepareForReplace())`()` Prepare the InsertHelper for a replace.                                                                                                                                                                                   |
| open[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | [replace](https://developer.android.com/reference/kotlin/android/database/DatabaseUtils.InsertHelper#replace(android.content.ContentValues))`(`values:` `[ContentValues](https://developer.android.com/reference/kotlin/android/content/ContentValues.html#)!`)` Performs an insert, adding a new row with the given values.                                      |

## Public constructors

### InsertHelper

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
InsertHelper(
    db: SQLiteDatabase!, 
    tableName: String!)
```

|                                                                       Parameters                                                                        ||
|-------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| `db`        | [SQLiteDatabase](https://developer.android.com/reference/kotlin/android/database/sqlite/SQLiteDatabase)!:the SQLiteDatabase to insert into |
| `tableName` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!:the name of the table to insert into                     |

## Public methods

### bind

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun bind(
    index: Int, 
    value: Boolean
): Unit
```

**Deprecated:** *Deprecated in Java.*

Bind the value to an index. A prepareForInsert() or prepareForReplace() without a matching execute() must have already have been called.

|                                                         Parameters                                                         ||
|---------|-------------------------------------------------------------------------------------------------------------------|
| `index` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the index of the slot to which to bind |
| `value` | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html):the value to bind              |

### bind

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun bind(
    index: Int, 
    value: ByteArray!
): Unit
```

**Deprecated:** *Deprecated in Java.*

Bind the value to an index. A prepareForInsert() or prepareForReplace() without a matching execute() must have already have been called.

|                                                         Parameters                                                         ||
|---------|-------------------------------------------------------------------------------------------------------------------|
| `index` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the index of the slot to which to bind |
| `value` | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)!:the value to bind        |

### bind

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun bind(
    index: Int, 
    value: Double
): Unit
```

**Deprecated:** *Deprecated in Java.*

Bind the value to an index. A prepareForInsert() or prepareForReplace() without a matching execute() must have already have been called.

|                                                         Parameters                                                         ||
|---------|-------------------------------------------------------------------------------------------------------------------|
| `index` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the index of the slot to which to bind |
| `value` | [Double](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-double/index.html):the value to bind                |

### bind

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun bind(
    index: Int, 
    value: Float
): Unit
```

**Deprecated:** *Deprecated in Java.*

Bind the value to an index. A prepareForInsert() or prepareForReplace() without a matching execute() must have already have been called.

|                                                         Parameters                                                         ||
|---------|-------------------------------------------------------------------------------------------------------------------|
| `index` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the index of the slot to which to bind |
| `value` | [Float](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html):the value to bind                  |

### bind

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun bind(
    index: Int, 
    value: Int
): Unit
```

**Deprecated:** *Deprecated in Java.*

Bind the value to an index. A prepareForInsert() or prepareForReplace() without a matching execute() must have already have been called.

|                                                         Parameters                                                         ||
|---------|-------------------------------------------------------------------------------------------------------------------|
| `index` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the index of the slot to which to bind |
| `value` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the value to bind                      |

### bind

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun bind(
    index: Int, 
    value: String!
): Unit
```

**Deprecated:** *Deprecated in Java.*

Bind the value to an index. A prepareForInsert() or prepareForReplace() without a matching execute() must have already have been called.

|                                                         Parameters                                                         ||
|---------|-------------------------------------------------------------------------------------------------------------------|
| `index` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the index of the slot to which to bind |
| `value` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!:the value to bind               |

### bind

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun bind(
    index: Int, 
    value: Long
): Unit
```

**Deprecated:** *Deprecated in Java.*

Bind the value to an index. A prepareForInsert() or prepareForReplace() without a matching execute() must have already have been called.

|                                                         Parameters                                                         ||
|---------|-------------------------------------------------------------------------------------------------------------------|
| `index` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the index of the slot to which to bind |
| `value` | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html):the value to bind                    |

### bindNull

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun bindNull(index: Int): Unit
```

**Deprecated:** *Deprecated in Java.*

Bind null to an index. A prepareForInsert() or prepareForReplace() without a matching execute() must have already have been called.

|                                                         Parameters                                                         ||
|---------|-------------------------------------------------------------------------------------------------------------------|
| `index` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the index of the slot to which to bind |

### close

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun close(): Unit
```

**Deprecated:** *Deprecated in Java.*

Close this object and release any resources associated with it. The behavior of calling`insert()`after calling this method is undefined.  

### execute

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun execute(): Long
```

**Deprecated:** *Deprecated in Java.*

Execute the previously prepared insert or replace using the bound values since the last call to prepareForInsert or prepareForReplace.

Note that calling bind() and then execute() is not thread-safe. The only thread-safe way to use this class is to call insert() or replace().

|                                                                     Return                                                                     ||
|------------------------------------------------------------------------------|------------------------------------------------------------------|
| [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | the row ID of the newly inserted row, or -1 if an error occurred |

### getColumnIndex

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun getColumnIndex(key: String!): Int
```

**Deprecated:** *Deprecated in Java.*

Returns the index of the specified column. This is index is suitagble for use in calls to bind().

|                                                Parameters                                                ||
|-------|---------------------------------------------------------------------------------------------------|
| `key` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!:the column name |

|                                               Return                                                ||
|----------------------------------------------------------------------------|-------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | the index of the column |

### insert

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun insert(values: ContentValues!): Long
```

**Deprecated:** *Deprecated in Java.*

Performs an insert, adding a new row with the given values. If the table contains conflicting rows, an error is returned.

|                                                                             Parameters                                                                              ||
|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
| `values` | [ContentValues](https://developer.android.com/reference/kotlin/android/content/ContentValues.html#)!:the set of values with which to populate the new row |

|                                                                     Return                                                                     ||
|------------------------------------------------------------------------------|------------------------------------------------------------------|
| [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | the row ID of the newly inserted row, or -1 if an error occurred |

### prepareForInsert

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun prepareForInsert(): Unit
```

**Deprecated:** *Deprecated in Java.*

Prepare the InsertHelper for an insert. The pattern for this is:

- prepareForInsert()
- bind(index, value);
- bind(index, value);
- ...
- bind(index, value);
- execute();

<br />

### prepareForReplace

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun prepareForReplace(): Unit
```

**Deprecated:** *Deprecated in Java.*

Prepare the InsertHelper for a replace. The pattern for this is:

- prepareForReplace()
- bind(index, value);
- bind(index, value);
- ...
- bind(index, value);
- execute();

<br />

### replace

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun replace(values: ContentValues!): Long
```

**Deprecated:** *Deprecated in Java.*

Performs an insert, adding a new row with the given values. If the table contains conflicting rows, they are deleted and replaced with the new row.

|                                                                             Parameters                                                                              ||
|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
| `values` | [ContentValues](https://developer.android.com/reference/kotlin/android/content/ContentValues.html#)!:the set of values with which to populate the new row |

|                                                                     Return                                                                     ||
|------------------------------------------------------------------------------|------------------------------------------------------------------|
| [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | the row ID of the newly inserted row, or -1 if an error occurred |