From Apache OpenOffice Wiki
Jump to: navigation, search

Understanding Connections

A connection is an open communication channel to a database. A connection is required to work with data in a database or with a database definition. Connections are encapsulated in Connection objects in the API. There are several possibilities to get a Connection:

  • Connect to a data source that has already been set up in the database context of API.
  • Use the driver manager or a specific driver to connect to a database without using an existing data source from the database context.
  • Get a connection from the connection pool maintained by API.
  • Reuse the connection of a database form which is currently open in the GUI.

With the above possibilities, a is made or at least a

The service has three main functions: communication, data definition and operation on the API application level. The service:

Connections are central to all database activities. The connection interfaces are discussed later.


The main interface of is Its methods control almost every aspect of communication with a database management system:

  // general connection control
  void close()
  boolean isClosed()
  void setReadOnly( [in] boolean readOnly)
  boolean isReadOnly()
  // commands and statements
  // - generic SQL statement
  // - prepared statement
  // - stored procedure call
  com::sun::star::sdbc::XStatement createStatement()
  com::sun::star::sdbc::XPreparedStatement prepareStatement( [in] string sql)
  com::sun::star::sdbc::XPreparedStatement prepareCall( [in] string sql)
  string nativeSQL( [in] string sql)
  // transactions
  void setTransactionIsolation( [in] long level)
  long getTransactionIsolation()
  void setAutoCommit( [in] boolean autoCommit)
  boolean getAutoCommit()
  void commit()
  void rollback()
  // database metadata
  com::sun::star::sdbc::XDatabaseMetaData getMetaData()
  // data type mapping (driver dependent)
  com::sun::star::container::XNameAccess getTypeMap()
  void setTypeMap( [in] com::sun::star::container::XNameAccess typeMap)
  // catalog (subspace in a database)
  void setCatalog( [in] string catalog)
  string getCatalog()

The use of commands and statements are explained in the sections Manipulating Data and Using DDL to Change the Database Design. Transactions are discussed in Using DBMS Features. Database metadata are covered in Retrieving Information about a Database.

The is a simple interface to handle SQL warnings:

  any getWarnings()
  void clearWarnings()

The exception is usually not thrown, rather it is transported silently to objects supporting Refer to the API reference for more information about SQL warnings.

Data Definition

The interfaces of are explained in the section Using SDBCX to Access the Database Design.

Operation on Application Level

Handling of query definitions through and is discussed in the section Queries .

Through get the necessary statement objects to open predefined queries and tables in a data source, and execute arbitrary SQL statements.

  com::sun::star::sdbc::XPreparedStatement prepareCommand( [in] string command, [in] long commandType)

If the value of the parameter is TABLE or QUERY, pass a table name or query name that exists in the of the connection. The value COMMAND makes prepareCommand() expect an SQL string. The result is a prepared statement object that can be parameterized and executed. For details and an example, refer to section PreparedStatement From DataSource Queries.

The interface accesses the parent of the connection, if available.

  com::sun::star::uno::XInterface getParent()
  void setParent( [in] com::sun::star::uno::XInterface Parent)
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages