Product Documentation

FairCom JDBC Developer's Guide

Previous Topic

Next Topic

Manage

Manage() provides data management functionality for your application and/or process.

Below is the code for Manage():

//

// Manage()

//

// This function performs record adds and updates using locking

//

private static void Manage ()

{

System.out.println("MANAGE");

// delete any existing records

Delete_Records();

// populate the table with data

Add_CustomerMaster_Records();

// display contents of table

Display_Records();

// update a record under locking control

Update_CustomerMaster_Record();

// display again after update and effects of lock

Display_Records();

}

//

// Delete_Records()

//

// This function deletes all the records in the table

//

private static void Delete_Records ()

{

System.out.println("\tDelete records...");

try

{

stmt.executeUpdate("DELETE FROM custmast");

}

catch (SQLException e)

{

Handle_Exception(e);

}

try

{

conn.commit();

}

catch (SQLException e)

{

Handle_Exception(e);

}

}

//

// Add_CustomerMaster_Records()

//

// This function adds records to table CustomerMaster from an

// array of strings

//

private static void Add_CustomerMaster_Records ()

{

System.out.println("\tAdd records...");

String data[] = {

"('1000','92867','CA','1','Bryan Williams','2999 Regency','Orange')",

"('1001','61434','CT','1','Michael Jordan','13 Main','Harford')",

"('1002','73677','GA','1','Joshua Brown','4356 Cambridge','Atlanta')",

"('1003','10034','MO','1','Keyon Dooling','19771 Park Avenue','Columbia')"

};

try

{

// add one record at time to table

for (int i = 0; i < data.length; i++) {

stmt.executeUpdate("INSERT INTO custmast VALUES " + data[i]);

}

}

catch (SQLException e)

{

Handle_Exception(e);

}

try

{

conn.commit();

}

catch (SQLException e)

{

Handle_Exception(e);

}

}

//

// Display_Records()

//

// This function displays the contents of a table.

//

private static void Display_Records ()

{

System.out.print("\tDisplay records...");

try

{

// execute a query statement

ResultSet rs = stmt.executeQuery ("SELECT * FROM custmast");

// fetch and display each individual record

while (rs.next()) {

System.out.println("\n\t\t" + rs.getString(1) + " " + rs.getString(5));

}

rs.close();

}

catch (SQLException e)

{

Handle_Exception(e);

}

}

//

// Update_CustomerMaster_Records()

//

// Update one record under locking control to demonstrate the effects

// of locking

//

private static void Update_CustomerMaster_Record()

{

System.out.println("\tUpdate record...");

try

{

stmt.executeUpdate("UPDATE custmast SET cm_custname = 'KEYON DOOLING' where cm_custnumb = '1003'");

System.out.println("\tPress <ENTER> key to unlock");

System.in.read(new byte[256]);

conn.commit();

}

catch (SQLException e)

{

Handle_Exception(e);

}

catch (Exception e)

{

Handle_Exception(e);

}

}

TOCIndex