Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this programming assignment, you (and one partner) will develop a program th

ID: 3834150 • Letter: F

Question

For this programming assignment, you (and one partner) will develop a program that maintains a database of 25 customers, including their first name, last name, date of birth, and social security number Currently the database contains data for 20 customers in an input file named customers.txt. Your program will utilize arrays and linked lists to store information about each customer. To maintain a high level of data security, the information will be separated between 2 different servers. Server1 is a linked list that holds the last name and the social security number. Server2 is an array of structs that holds the first name and the date of birth. To link the 2 servers you must create an 8-bit encrypted array of characters (for each customer) that both servers use to access/store the information. In addition to setting up the 2 servers with the initial customer information (from the input file), your program should provide a menu for the system administrator to complete the following operations: add a new customer delete a customer print the entire customer database to an output file. Each customer record should print in the following order: social security number, last name, first name, and date of birth Additional Notes: Your program must contain at least three (3) user-defined functions You are to name your output file in the following format: .txt Successful completion of this assignment includes (but is not limited to): Use of an array of structures, linked lists and at least 3 appropriate functions Properly named .cpp file and output file Inclusion of the algorithm used to develop your program as comments within your program A program that compiles and executes properly A menu-driven program that properly implements the aforementioned operations.

Explanation / Answer

import java.net.URL; import java.sql.*; import java.io.PrintWriter; class TestDatabase { public static void main (String args[]) { try { // Load driver's class, inilialize, register with DriverManager //Class.forName("oracle.jdbc.driver.OracleDriver"); Class.forName("org.gjt.mm.mysql.Driver"); } catch (ClassNotFoundException e) { System.out.println("Unable to load driver class"); return; } ResultSet rs = null; try { // // Call DriverManager's methods (all are static) // // To print log on sysout //DriverManager.setLogStream(System.out); //JDBC 1.x driver DriverManager.setLogWriter(new PrintWriter(System.out) ); // Connect to database. DriverManager loads each registered driver // in turn until one can handle the database URL format //Connection con = DriverManager.getConnection( // "jdbc:oracle:thin:@host.domain.com:1521:db_name" // ,"scott","tiger"); Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/civil2","",""); // Check for warnings generated during connect areWarnings(con.getWarnings() ); // Get the DatabaseMetaData object to display database info DatabaseMetaData dmd = con.getMetaData(); // Display overall database info System.out.println( " Connected to " + dmd.getURL() + " using driver = " + dmd.getDriverName() + ", version = " + dmd.getDriverVersion() ); System.out.println( " Vendor product name is " + dmd.getDatabaseProductName() + ". Database software version is " + dmd.getDatabaseProductVersion() + ". User name is " + dmd.getUserName() + ". Catalog is called " + dmd.getCatalogTerm() + ". Schema is called " + dmd.getSchemaTerm() + ". Procedure is called " + dmd.getProcedureTerm() + "." ); System.out.println( " Numeric functions are: " + dmd.getNumericFunctions() + " String functions are: " + dmd.getStringFunctions() + " Date and Time functions are: " + dmd.getTimeDateFunctions() + " System functions are: " + dmd.getSystemFunctions() + " " ); System.out.println( "Use the escape string "" + dmd.getSearchStringEscape() + "" to escape wildcard characters." ); System.out.println( "Is the database in read only mode? Answer: " + dmd.isReadOnly() + "" ); // Create a Statement object for submitting SQL commands to driver Statement stmt = con.createStatement(); String sql; //DROP TABLE statement sql = "DROP TABLE users"; try { stmt.executeUpdate(sql); //throws SQLExecption if fails System.out.println("Dropped table "users"!"); } catch(SQLException ex) { System.out.println("Could not drop table "users"!"); printException(ex); } areWarnings(stmt.getWarnings() ); //CREATE TABLE statement sql = "CREATE TABLE users (" + "login VARCHAR(30) PRIMARY KEY NOT NULL," + "password VARCHAR(100)," + "first VARCHAR(50)," + "middle VARCHAR(50)," + "last VARCHAR(50)," + "nickname VARCHAR(30)," + "email VARCHAR(100)," + "city VARCHAR(50)," + "state VARCHAR(50)," + "country VARCHAR(50)," + "zip VARCHAR(30)" + ")"; try { stmt.executeUpdate(sql); //throws SQLExecption if fails System.out.println("Created table "users"!"); } catch(SQLException ex) { printException(ex); } areWarnings(stmt.getWarnings() ); // // More Database meta data // // What type of tables (tables, views etc.)? rs = dmd.getTableTypes(); printResultSet(rs); rs.close(); // Any catalogs? rs = dmd.getCatalogs(); printResultSet(rs); rs.close(); // What are the defined schemas? rs = dmd.getSchemas(); printResultSet(rs); rs.close(); // Good One: What are the defined tables? // Last arg is an array of strings (table types to get) //String[] tp = {"TABLE"}; //rs = dmd.getTables(null, null, "addr%", null); rs = dmd.getTables(null, null, null, null); printResultSet(rs); rs.close(); // For a table, what are the defined indexes? rs = dmd.getIndexInfo(null, null, "users", false, true); printResultSet(rs); rs.close(); // For a table, what columns nake up its primary key rs = dmd.getPrimaryKeys(null, null, "users"); printResultSet(rs); rs.close(); // Any stored procedures defined? rs = dmd.getProcedures(null, null, null); printResultSet(rs); rs.close(); // The connected user has these table privileges rs = dmd.getTablePrivileges(null, null, null); printResultSet(rs); rs.close(); // The connected user has these column privileges rs = dmd.getColumnPrivileges(null, null, null, null); printResultSet(rs); rs.close(); // Get all the tables with their column definitions rs = dmd.getColumns(null, null, null, null); printResultSet(rs); rs.close(); // INSERT statement (UPDATE is similar) sql = "INSERT INTO users (" + "login, password, nickname, " + "last, first, middle, email," + "city, state, country, zip" + ") VALUES (" + "'superman', 'foo has a meaning', 'S'," + "NULL, NULL, NULL, 'iam@your.place'," + "NULL, NULL, NULL, '56735-6453'" + ")"; stmt.executeUpdate(sql); //throws SQLExecption if fails areWarnings(stmt.getWarnings() ); // Submit a query, driver hands back a ResultSet object sql = "SELECT * FROM users WHERE login IS NOT NULL"; rs = stmt.executeQuery(sql); //throws SQLExecption if fails areWarnings(stmt.getWarnings() ); // Process query results. printResultSet(rs); // Tell Java you are done and Java may release memory rs.close(); // DELETE statement sql = "DELETE FROM users WHERE login IS NOT NULL"; stmt.executeUpdate(sql); //throws SQLExecption if fails areWarnings(stmt.getWarnings() ); // Good people close explicitly to release db resources stmt.close(); con.close(); } catch(SQLException ex){printException(ex); } } // // Work with ResultSetMetaData // private static void printResultSet(ResultSet rs) throws SQLException { ResultSetMetaData rsmd = rs.getMetaData(); int numCols = rsmd.getColumnCount(); // Display column titles System.out.println("-----------------------------------------"); for(int i=1; i 1) System.out.print(","); System.out.print(rsmd.getColumnLabel(i)); } System.out.println(""); System.out.println("-----------------------------------------"); // Display data, fetching until end of the result set // Calling next moves to first or next row and returns true if success while(rs.next() ) { // Each rs after next() contains next rows data for(int i=1; i 1) System.out.print(","); // Almost all SQL types can be cast to a string by JDBC System.out.print(rs.getString(i)); areWarnings(rs.getWarnings() ); } System.out.println(""); } } // // Check for warnings // private static boolean areWarnings(SQLWarning warn) throws SQLException { boolean rc = false; // Multiple warning smay have been chained to the passed SQLWarning object // Or, null may have been passed if there were no warnings if(warn != null) { System.out.println(" *** Warning *** "); rc = true; while(warn != null) { System.out.println("SQLState: " + warn.getSQLState() ); System.out.println("Message: " + warn.getMessage() ); System.out.println("Vendor: " + warn.getErrorCode ()); System.out.println (""); warn = warn.getNextWarning (); } } return rc; } // // Print all chained exceptions // public static void printException(SQLException ex) { // Multiple error objects may be chained together System.out.println(" *** SQLException caught *** "); while(ex != null) { System.out.println("SQLState: " + ex.getSQLState() ); System.out.println("Message: " + ex.getMessage() ); System.out.println("Vendor: " + ex.getErrorCode ()); ex.printStackTrace(System.out); System.out.println (""); // Get next error object in chain. null if none. ex = ex.getNextException(); } } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote