com.softtech.jdbc
Class SampleCodeUsingFramework

java.lang.Object
  extended by com.softtech.jdbc.SampleCodeUsingFramework

public class SampleCodeUsingFramework
extends java.lang.Object

This class contains static methods for testing the JDBC framework code.

Author:
Jeff S Smith

Field Summary
private static java.lang.String connURL
          JDBC connection URL
private static java.lang.String driverName
          JDBC driver name
private static java.lang.String password
          JDBC connection password
(package private) static java.lang.String sqlSelect
          select statement used by some test methods
private static java.lang.String username
          JDBC connection username
 
Constructor Summary
SampleCodeUsingFramework()
           
 
Method Summary
private static void applyDataIntegrityViolationRecovery()
          Dummy method (placeholder) for recovery method
static ConnectionPool getConnectionPool()
          Creates a new connection pool object
static void main(java.lang.String[] args)
          static main method testing jdbc framework with various method calls
private static void setHSQLConnectInfo()
          Sets fields to values required to connect to a sample HSQL database
private static void setMySQLConnectInfo()
          Sets fields to values required to connect to a sample MySQL database
private static void setOracleConnectInfo()
          Sets fields to values required to connect to a sample ORACLE database
private static void setPostgreSQLConnectInfo()
          Sets fields to values required to connect to a sample PostgreSQL database
static void testCallingStoredProc()
          This procecure calls the following Oracle stored procedure which inserts a new row into the JDBC_TEST table.
static void testCallingStoredProcWithAnOUTParam()
          This procedure calls the following Oracle stored procedure and gets the value from the OUT param pFULLNAME.
static void testConnectionPooling()
          Creates a connection pool (2 connections) and execututes queries on each.
static void testCreatingOwnConnection()
          Illustrates creating a database connection using standard JDBC and then using this connection to create a ConnectionPool and execute a select statement.
static void testDeadlockException()
          static method testing jdbc framework with a select for update statement (that locks a record) and an update statement that generates a deadlock.
static void testDeleteAndInsert()
          static method testing jdbc framework with a delete and an insert statement
static void testHSQL()
           
static void testMultipleUpdatesAndTrans()
          static method testing jdbc framework with multiple updates, using transaction management
static void testMultipleUpdatesAndTransWithException()
          static method testing jdbc framework with multiple updates and intentional sql exceptions that are trapped in appropriate exception handling blocks
static void testMySQL()
          Does a simple select from a MySQL database.
static void testOracleStoredFunction()
          This method tests the jdbc framework with a call to the following Oracle stored function: CREATE OR REPLACE FUNCTION jdbc_test1 RETURN NUMBER IS cnt_jdbc_test NUMBER; BEGIN dbms_output.put_line ('starting jdbc_test1...'); cnt_jdbc_test := 0; SELECT COUNT(*) INTO cnt_jdbc_test FROM JDBC_TEST; RETURN cnt_jdbc_test; EXCEPTION WHEN NO_DATA_FOUND THEN Null; WHEN OTHERS THEN -- Consider logging the error and then re-raise RAISE; END jdbc_test1; /
static void testParameterizedQuery()
          Run a parameterized query (sql) once with one parameter and then again with another parameter.
static void testSelectDistinctAndMixedCase()
           
static void testSelectWhichReturnsNoRows()
          static method testing jdbc framework with a simple select statement that returns no rows
static void testSimpleSelectAndMaxRows()
          static method testing jdbc framework with a simple select statement, parameters, and a maximum number of rows
static void testSimpleSelectWithParams()
          static method testing jdbc framework with a simple select statement using parameters
static void testSimpleSelectWithParamsAndToString()
          static method testing jdbc framework with a simple select statement using parameters and the result set's .toString() method
static void testStandardJDBC()
          static method executes a standard jdbc query
static void testThis()
           
static void testUpdate()
          static method testing jdbc framework with an update statement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

driverName

private static java.lang.String driverName
JDBC driver name


connURL

private static java.lang.String connURL
JDBC connection URL


username

private static java.lang.String username
JDBC connection username


password

private static java.lang.String password
JDBC connection password


sqlSelect

static java.lang.String sqlSelect
select statement used by some test methods

Constructor Detail

SampleCodeUsingFramework

public SampleCodeUsingFramework()
Method Detail

setMySQLConnectInfo

private static void setMySQLConnectInfo()
Sets fields to values required to connect to a sample MySQL database


setPostgreSQLConnectInfo

private static void setPostgreSQLConnectInfo()
Sets fields to values required to connect to a sample PostgreSQL database


setOracleConnectInfo

private static void setOracleConnectInfo()
Sets fields to values required to connect to a sample ORACLE database


setHSQLConnectInfo

private static void setHSQLConnectInfo()
Sets fields to values required to connect to a sample HSQL database


applyDataIntegrityViolationRecovery

private static void applyDataIntegrityViolationRecovery()
Dummy method (placeholder) for recovery method


testStandardJDBC

public static void testStandardJDBC()
static method executes a standard jdbc query


getConnectionPool

public static ConnectionPool getConnectionPool()
Creates a new connection pool object

Returns:
ConnectionPool

testSimpleSelectWithParams

public static void testSimpleSelectWithParams()
static method testing jdbc framework with a simple select statement using parameters


testSimpleSelectWithParamsAndToString

public static void testSimpleSelectWithParamsAndToString()
static method testing jdbc framework with a simple select statement using parameters and the result set's .toString() method


testSimpleSelectAndMaxRows

public static void testSimpleSelectAndMaxRows()
static method testing jdbc framework with a simple select statement, parameters, and a maximum number of rows


testOracleStoredFunction

public static void testOracleStoredFunction()
This method tests the jdbc framework with a call to the following Oracle stored function: CREATE OR REPLACE FUNCTION jdbc_test1 RETURN NUMBER IS cnt_jdbc_test NUMBER; BEGIN dbms_output.put_line ('starting jdbc_test1...'); cnt_jdbc_test := 0; SELECT COUNT(*) INTO cnt_jdbc_test FROM JDBC_TEST; RETURN cnt_jdbc_test; EXCEPTION WHEN NO_DATA_FOUND THEN Null; WHEN OTHERS THEN -- Consider logging the error and then re-raise RAISE; END jdbc_test1; /


testDeleteAndInsert

public static void testDeleteAndInsert()
static method testing jdbc framework with a delete and an insert statement


testUpdate

public static void testUpdate()
static method testing jdbc framework with an update statement


testMultipleUpdatesAndTrans

public static void testMultipleUpdatesAndTrans()
static method testing jdbc framework with multiple updates, using transaction management


testMultipleUpdatesAndTransWithException

public static void testMultipleUpdatesAndTransWithException()
static method testing jdbc framework with multiple updates and intentional sql exceptions that are trapped in appropriate exception handling blocks


testSelectWhichReturnsNoRows

public static void testSelectWhichReturnsNoRows()
static method testing jdbc framework with a simple select statement that returns no rows


testDeadlockException

public static void testDeadlockException()
static method testing jdbc framework with a select for update statement (that locks a record) and an update statement that generates a deadlock.


testCreatingOwnConnection

public static void testCreatingOwnConnection()
Illustrates creating a database connection using standard JDBC and then using this connection to create a ConnectionPool and execute a select statement.


testMySQL

public static void testMySQL()
Does a simple select from a MySQL database.


testConnectionPooling

public static void testConnectionPooling()
Creates a connection pool (2 connections) and execututes queries on each. It then tries to get a third connection.


testSelectDistinctAndMixedCase

public static void testSelectDistinctAndMixedCase()

testCallingStoredProc

public static void testCallingStoredProc()
This procecure calls the following Oracle stored procedure which inserts a new row into the JDBC_TEST table. CREATE OR REPLACE PROCEDURE jdbc_proc_test1(pTEST_ID NUMBER, pNOTES VARCHAR2) IS BEGIN INSERT INTO JDBC_TEST(TEST_ID, NOTES, TEST_DT, AMOUNT, CODE) VALUES (pTEST_ID, pNOTES, SYSDATE, 44.44, 'Z'); END; /


testCallingStoredProcWithAnOUTParam

public static void testCallingStoredProcWithAnOUTParam()
This procedure calls the following Oracle stored procedure and gets the value from the OUT param pFULLNAME. CREATE OR REPLACE PROCEDURE jdbc_proc_test2( pFIRSTNAME IN VARCHAR2, pLASTNAME IN VARCHAR2, pFULLNAME OUT VARCHAR2) IS BEGIN pFULLNAME := pFIRSTNAME || ' ' || pLASTNAME; END;


testParameterizedQuery

public static void testParameterizedQuery()
Run a parameterized query (sql) once with one parameter and then again with another parameter. Since the sql doesn't change from the first call to runQuery() to the second call, the runQuery() method only prepares the SQL statement once (the first time it is called). This was verified with the debugger.


testThis

public static void testThis()

testHSQL

public static void testHSQL()

main

public static void main(java.lang.String[] args)
static main method testing jdbc framework with various method calls

Parameters:
args -