|
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--coreservlets.DatabaseUtilities
Three database utilities:
1) getQueryResults. Connects to a database, executes
a query, retrieves all the rows as arrays
of strings, and puts them inside a DBResults
object. Also places the database product name,
database version, and the names of all the columns
into the DBResults object. This has two versions:
one that makes a new connection and another that
uses an existing connection.
2) createTable. Given a table name, a string denoting the column formats, and an array of strings denoting the row values, this method connects to a database, removes any existing versions of the designated table, issues a CREATE TABLE command with the designated format, then sends a series of INSERT INTO commands for each of the rows. Again, there are two versions: one that makes a new connection and another that uses an existing connection.
3) printTable. Given a table name, this connects to the specified database, retrieves all the rows, and prints them on the standard output.
Taken from Core Servlets and JavaServer Pages from Prentice Hall and Sun Microsystems Press, http://www.coreservlets.com/. © 2000 Marty Hall; may be freely used or adapted.
| Constructor Summary | |
DatabaseUtilities()
|
|
| Method Summary | |
static Connection |
createTable(Connection connection,
String username,
String password,
String tableName,
String tableFormat,
String[] tableRows,
boolean close)
Like the previous method, but uses existing connection. |
static Connection |
createTable(String driver,
String url,
String username,
String password,
String tableName,
String tableFormat,
String[] tableRows,
boolean close)
Build a table with the specified format and rows. |
static DBResults |
getQueryResults(Connection connection,
String query,
boolean close)
Retrieves results as in previous method but uses an existing connection instead of opening a new one. |
static DBResults |
getQueryResults(String driver,
String url,
String username,
String password,
String query,
boolean close)
Connect to database, execute specified query, and accumulate results into DBRresults object. |
static void |
printTable(Connection connection,
String tableName,
int entryWidth,
boolean close)
Prints out all entries in a table. |
static void |
printTable(String driver,
String url,
String username,
String password,
String tableName,
int entryWidth,
boolean close)
|
static void |
printTableData(String tableName,
DBResults results,
int entryWidth,
boolean printMetaData)
|
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Constructor Detail |
public DatabaseUtilities()
| Method Detail |
public static DBResults getQueryResults(String driver,
String url,
String username,
String password,
String query,
boolean close)
public static DBResults getQueryResults(Connection connection,
String query,
boolean close)
public static Connection createTable(String driver,
String url,
String username,
String password,
String tableName,
String tableFormat,
String[] tableRows,
boolean close)
public static Connection createTable(Connection connection,
String username,
String password,
String tableName,
String tableFormat,
String[] tableRows,
boolean close)
public static void printTable(String driver,
String url,
String username,
String password,
String tableName,
int entryWidth,
boolean close)
public static void printTable(Connection connection,
String tableName,
int entryWidth,
boolean close)
public static void printTableData(String tableName,
DBResults results,
int entryWidth,
boolean printMetaData)
|
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
![]() |
|---|
| CSAJSP @ amazon.com |