|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.partnersoft.sql.SqlConnection
public class SqlConnection
A connection to an SqlDatabase. This is a wrapper around a standard Java SQL Connection. Uses SqlDatabase to configure; supports resetting the connection, and has lots of convenience functions for scripts and other activities.
Copyright 2003-2008 Partner Software, Inc.
| Constructor Summary | |
|---|---|
SqlConnection(SqlDatabase config)
|
|
| Method Summary | |
|---|---|
void |
close()
|
void |
connect()
Connects to the database using a SqlDatabase for configuration. |
int |
countQuery(java.lang.String tableName,
java.lang.Object... wheres)
This runs a simple "select count(FOO) from BAR where FOO=BAZ and BIZZLE=BAZZLE..." and returns the count. |
java.sql.Statement |
createReadOnlyStatement()
Creates a read only statement. |
java.sql.Statement |
createReadWriteStatement()
Creates a read/write statement. |
DataRecordSource |
createRecordSource(DataRecordQuery query,
CogStructureType tableType)
Returns a DataRecordSource for the passed query, or null if an SQLException occurs. |
java.sql.Statement |
createStatement()
Convenience method that calls createReadOnlyStatement(). |
void |
disconnect()
|
void |
execute(java.sql.PreparedStatement statement,
java.lang.Object... parameters)
Executes the prepared statement with the given parameters. |
void |
execute(java.lang.String sql)
Executes a sql query. |
void |
execute(java.lang.String sql,
java.util.LinkedList<java.lang.Object> parameters)
Prepares a statement and executes it - uses a linked list. |
void |
execute(java.lang.String sql,
java.lang.Object... parameters)
Prepares a statement and executes it. |
java.sql.Connection |
getConnection()
|
SqlDatabase |
getDatabase()
|
SqlType |
getType()
|
boolean |
insertOrUpdate(java.lang.String tableName,
java.lang.String keyField,
Naming<java.lang.Object> values)
Inserts or updates the given data into the given table. |
boolean |
isConnected()
|
java.util.List<java.lang.String> |
listCatalogs()
Requires a valid DatabaseConnection. |
java.util.List<java.lang.String> |
listColumns(java.lang.String tableName)
Requires a valid DatabaseConnection. |
java.util.List<java.lang.String> |
listSchemas()
Requires a valid DatabaseConnection. |
java.util.List<java.lang.String> |
listTableNames()
|
Naming<java.lang.String> |
listTableOwners()
Requires a valid DatabaseConnection. |
java.util.List<SqlTable> |
listTables()
Requires a valid DatabaseConnection. |
Naming<java.lang.Object> |
namingQuery(java.lang.String sql,
java.lang.Object... parameters)
Runs the given query, which should have two columns in it, a key and a value. |
java.util.List<java.lang.Object> |
oneColumnQuery(java.lang.String sql)
Runs a query that should only return a single column of values. |
java.util.List<java.lang.Object> |
oneColumnQuery(java.lang.String sql,
java.lang.Object... parameters)
Runs a query that should only return a single column of values. |
java.lang.Object |
oneFieldQuery(java.lang.String sql)
Runs a query with a single result row and column and returns the value. |
java.lang.Object |
oneFieldQuery(java.lang.String sql,
java.lang.Object... parameters)
Runs a query with a single result row and column and returns the value. |
Naming<java.lang.Object> |
oneRowQuery(java.lang.String sql)
Runs a query that should only return a single row of values. |
Naming<java.lang.Object> |
oneRowQuery(java.lang.String sql,
java.lang.Object... parameters)
Runs a query that should only return a single row of values. |
java.sql.PreparedStatement |
prepareStatement(java.lang.String query)
Creates a PreparedStatement. |
SqlDataRecordSource |
query(java.lang.String sql)
Runs the given query, returning the results as an SQLDataRecordSource object (which can actually be run multiple times). |
SqlDataRecordSource |
query(java.lang.String sql,
java.lang.Object... args)
Runs the given query, returning the results as an SQLDataRecordSource object (which can actually be run multiple times). |
void |
runScript(java.lang.String sqlScript)
|
SqlTable |
tableNamed(java.lang.String name)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SqlConnection(SqlDatabase config)
| Method Detail |
|---|
public void connect()
throws java.sql.SQLException
java.sql.SQLException
public void disconnect()
throws java.sql.SQLException
java.sql.SQLExceptionpublic java.sql.Connection getConnection()
public boolean isConnected()
public java.sql.Statement createStatement()
throws java.sql.SQLException
createReadOnlyStatement().
java.sql.SQLException
public java.sql.Statement createReadOnlyStatement()
throws java.sql.SQLException
Connects if necessary.
java.sql.SQLException
public java.sql.Statement createReadWriteStatement()
throws java.sql.SQLException
Connects if necessary
java.sql.SQLException
public void close()
throws java.sql.SQLException
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String query)
throws java.sql.SQLException
Connects if necessary.
query - SQL query to prepare for execution; may contain placeholders
java.sql.SQLException
public void execute(java.lang.String sql)
throws java.sql.SQLException
Connects if necessary.
sql -
java.sql.SQLException
public void execute(java.lang.String sql,
java.lang.Object... parameters)
throws java.sql.SQLException
Will connect if necessary
Usage:
execute("select * from whatever where id = ? and otherID = ?", idObject, otherIDObject);
sql - parameters -
java.sql.SQLException
public void execute(java.lang.String sql,
java.util.LinkedList<java.lang.Object> parameters)
throws java.sql.SQLException
Will connect if necessary
Usage:
execute("select * from whatever where id = ? and otherID = ?", idObject, otherIDObject);
sql -
java.sql.SQLException
public void execute(java.sql.PreparedStatement statement,
java.lang.Object... parameters)
throws java.sql.SQLException
Will connect if necessary
Usage example:
statement = prepareInsertStatement("sometable", "id", "otherID");
execute(statement, idObject, otherIDObject);
statement - parameters -
java.sql.SQLException
public void runScript(java.lang.String sqlScript)
throws java.sql.SQLException
java.sql.SQLException
public int countQuery(java.lang.String tableName,
java.lang.Object... wheres)
throws java.sql.SQLException
Requires an valid DatabaseConnection.
tableName - name of tablewheres - list of names and values, alternating
java.sql.SQLException
public java.lang.Object oneFieldQuery(java.lang.String sql)
throws java.sql.SQLException
sql -
java.sql.SQLException
public java.lang.Object oneFieldQuery(java.lang.String sql,
java.lang.Object... parameters)
throws java.sql.SQLException
Requires an valid DatabaseConnection.
sql - parameters -
java.sql.SQLException
public Naming<java.lang.Object> oneRowQuery(java.lang.String sql)
throws java.sql.SQLException
Requires a valid DatabaseConnection.
sql -
java.sql.SQLException
public Naming<java.lang.Object> oneRowQuery(java.lang.String sql,
java.lang.Object... parameters)
throws java.sql.SQLException
Requires a valid DatabaseConnection.
sql - parameters -
java.sql.SQLException
public java.util.List<java.lang.Object> oneColumnQuery(java.lang.String sql)
throws java.sql.SQLException
Requires a valid DatabaseConnection.
sql -
java.sql.SQLException
public java.util.List<java.lang.Object> oneColumnQuery(java.lang.String sql,
java.lang.Object... parameters)
throws java.sql.SQLException
Requires a valid DatabaseConnection.
sql - parameters -
java.sql.SQLException
public Naming<java.lang.Object> namingQuery(java.lang.String sql,
java.lang.Object... parameters)
throws java.sql.SQLException
Requires a valid DatabaseConnection.
sql - parameters -
java.sql.SQLExceptionpublic SqlDataRecordSource query(java.lang.String sql)
public SqlDataRecordSource query(java.lang.String sql,
java.lang.Object... args)
PreparedStatement.
public java.util.List<SqlTable> listTables()
throws java.sql.SQLException
java.sql.SQLException
public java.util.List<java.lang.String> listTableNames()
throws java.sql.SQLException
java.sql.SQLException
public Naming<java.lang.String> listTableOwners()
throws java.sql.SQLException
java.sql.SQLException
public java.util.List<java.lang.String> listCatalogs()
throws java.sql.SQLException
java.sql.SQLException
public java.util.List<java.lang.String> listSchemas()
throws java.sql.SQLException
java.sql.SQLException
public java.util.List<java.lang.String> listColumns(java.lang.String tableName)
throws java.sql.SQLException
tableName -
java.sql.SQLException
public boolean insertOrUpdate(java.lang.String tableName,
java.lang.String keyField,
Naming<java.lang.Object> values)
throws java.sql.SQLException
java.sql.SQLException
public SqlTable tableNamed(java.lang.String name)
throws java.sql.SQLException
java.sql.SQLExceptionpublic SqlDatabase getDatabase()
public SqlType getType()
public DataRecordSource createRecordSource(DataRecordQuery query,
CogStructureType tableType)
createRecordSource in interface DataRecordSourceFactoryquery - tableType -
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||