Product Documentation

FairCom JDBC

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 simple record functions of add, delete and gets

//

private static void Manage ()

{

System.out.println("MANAGE");

// delete any existing records

Delete_Records();

// populate the table with data

Add_Records();

// display contents of table

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);

}

}

//

// Add_Records()

//

// This function adds records to a table in the database from an

// array of strings

//

private static void Add_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);

}

}

//

// 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);

}

}

TOCIndex