JavaXT
|
|||||||||
Database ClassUsed to encapsulate database connection information, open connections to the database, and execute queries.
Constructors Database( )
Database( String name, String host, int port, String username, String password, Driver driver )
Public MethodssetName( String name ) returns void Sets the name of the catalog used to store tables, views, etc. setHost( String host, int port ) returns void Used to set the path to the database (server name and port). setHost( String host ) returns void Used to set the path to the database.
getHost( ) returns String Returns the name or IP address of the server or a physical path to the database file. setDriver( String driver ) returns void Used to find a driver that corresponds to a given vendor name, class name, or protocol. getConnectionString( ) returns String Returns a JDBC connection string used to connect to the database. Username and password are appended to the end of the url. getConnection( ) returns Connection Returns a connection to the database. If a connection pool has been initialized, a connection is returned from the pool. Otherwise, a new connection is created. In either case, the connection must be closed immediately after use. See Connection.close() for details. initConnectionPool( ) returns void Used to initialize a connection pool. Subsequent called to the getConnection() method will return connections from the pool. initConnectionPool( ConnectionPool cp ) returns void Used to configure the Database class to use a specific instance of a javaxt.sql.ConnectionPool. Subsequent called to the getConnection() method will return connections from the pool.
terminateConnectionPool( ) returns void Used to terminate the connection pool, closing all active connections. setConnectionPoolSize( int maxConnections ) returns void Used to specify the size of the connection pool. The pool size must be set before initializing the connection pool. If the pool size is not defined, the connection pool will default to 15. getConnectionPool( ) returns ConnectionPool Returns the connection pool that was created via the initConnectionPool method. Returns null if the connection pool has not been not initialized or if the connection pool has been terminated. setConnectionPoolDataSource( ConnectionPoolDataSource dataSource ) returns void Used to set the ConnectionPoolDataSource for the database. Typically, the getConnectionPoolDataSource() method is used to create a ConnectionPoolDataSource. This method allows you to specify a different ConnectionPoolDataSource. getConnectionPoolDataSource( ) returns ConnectionPoolDataSource Used to instantiate a ConnectionPoolDataSource for the database. The ConnectionPoolDataSource is typically used to create a JDBC Connection Pool. getRecord( String sql ) returns javaxt.sql.Record Used to retrieve a single record from this database. getRecords( String sql ) returns Iterable<javaxt.sql.Record> Used to retrieve records from this database. Note that this method relies on a Generator to yield records. This is fine for relatively small record sets. However, for large record sets, we recommend opening a database connection first and calling Connection.getRecords() like this:
try (Connection conn = database.getConnection()){ return conn.getRecords(sql); } getTables( ) returns Table[] Used to retrieve an array of tables and columns found in this database. getTableNames( ) returns String[] Used to retrieve an array of table names found in the database. If a table is part of a schema, the schema name is prepended to the table name. This method is significantly faster than the getTables() method which returns the full metadata for each table. getCatalogs( ) returns String[] Used to retrieve a list of available catalogs (aka databases) found on this server. getReservedKeywords( ) returns String[] Returns a list of reserved keywords for the current database. enableMetadataCache( boolean b ) returns void Used to enable/disable metadata caching. If caching is enabled, calls to getTables() and getCatalogs() will return cached results. This is appropriate if the database schema doesn't change often and may increase performance when inserting and updating records via the Recordset class.
addModel( Class c ) returns void Used to register a javaxt.sql.Model with the database. The model is initialized and associated with the database connection pool. Once the model is initialized, it can be used to find records in the database and execute CRUD operations.
toString( ) returns String Returns database connection information encapsulated by this class. Static MethodsgetTables( Connection conn ) returns Table[] Used to retrieve an array of tables and columns found in a database. getCatalogs( Connection conn ) returns String[] Used to retrieve a list of available catalogs (aka databases) found on a server. getReservedKeywords( Connection conn ) returns String[] Returns a list of reserved keywords for a given database. |