# Class: SQLConnection

## vertx-sql-js/sql_connection~ SQLConnection

#### new SQLConnection()

  Represents a connection to a SQL database
  Source:
    - sql_connection.js, line 31

### Methods

#### close(handler)

  Closes the connection. Important to always close the connection when you are done so it's returned to the pool.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `handler` | function | the handler called when this operation completes.

  Source:
    - sql_connection.js, line 178

#### commit(handler) → {SQLConnection}

  Commits all changes made since the previous commit/rollback.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `handler` | function | the handler called when this operation completes.

  Source:
    - sql_connection.js, line 200

  ##### Returns:

  Type
    SQLConnection

#### execute(sql, resultHandler) → {SQLConnection}

  Executes the given SQL statement

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `sql` | string | the SQL to execute. For example `CREATE TABLE IF EXISTS table ...`
  `resultHandler` | function | the handler which is called once this operation completes.

  Source:
    - sql_connection.js, line 66

  ##### Returns:

  Type
    SQLConnection

#### query(sql, resultHandler) → {SQLConnection}

  Executes the given SQL `SELECT` statement which returns the results of the query.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `sql` | string | the SQL to execute. For example `SELECT * FROM table ...`.
  `resultHandler` | function | the handler which is called once the operation completes. It will return a ResultSet.

  Source:
    - sql_connection.js, line 88

  ##### Returns:

  Type
    SQLConnection

#### queryWithParams(sql, params, resultHandler) → {SQLConnection}

  Executes the given SQL `SELECT` prepared statement which returns the results of the query.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `sql` | string | the SQL to execute. For example `SELECT * FROM table ...`.
  `params` | todo | these are the parameters to fill the statement.
  `resultHandler` | function | the handler which is called once the operation completes. It will return a ResultSet.

  Source:
    - sql_connection.js, line 111

  ##### Returns:

  Type
    SQLConnection

#### rollback(handler) → {SQLConnection}

  Rolls back all changes made since the previous commit/rollback.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `handler` | function | the handler called when this operation completes.

  Source:
    - sql_connection.js, line 221

  ##### Returns:

  Type
    SQLConnection

#### setAutoCommit(autoCommit, resultHandler) → {SQLConnection}

  Sets the auto commit flag for this connection. True by default.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `autoCommit` | boolean | the autoCommit flag, true by default.
  `resultHandler` | function | the handler which is called once this operation completes.

  Source:
    - sql_connection.js, line 44

  ##### Returns:

  Type
    SQLConnection

#### update(sql, resultHandler) → {SQLConnection}

  Executes the given SQL statement which may be an `INSERT`, `UPDATE`, or `DELETE` statement.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `sql` | string | the SQL to execute. For example `INSERT INTO table ...`
  `resultHandler` | function | the handler which is called once the operation completes.

  Source:
    - sql_connection.js, line 134

  ##### Returns:

  Type
    SQLConnection

#### updateWithParams(sql, params, resultHandler) → {SQLConnection}

  Executes the given prepared statement which may be an `INSERT`, `UPDATE`, or `DELETE` statement with the given parameters

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `sql` | string | the SQL to execute. For example `INSERT INTO table ...`
  `params` | todo | these are the parameters to fill the statement.
  `resultHandler` | function | the handler which is called once the operation completes.

  Source:
    - sql_connection.js, line 158

  ##### Returns:

  Type
    SQLConnection