PROJECT 2
25 Points
This project will create an Java application to provide maintenance for the Star Ship Enterprise crew members. It will consist of a Menu, Addition, Inquiry, Change, and Delete form. JDeveloper's User Interface Editor (UI Editor) will be used to design and create these forms using Java's Swing components.
Menu form:

Inquiry form: Addition form:

Change form: Delete form:

Provide error messages using Java's JOptionPane.showMessageDialog() for the following conditions (display SSN with -'s).
Not found: Duplicate record:

Invalid SSN:

Specifications:
- All forms The SSN is to be displayed with -'s
- Menu form Be centered on the screen.
When displayed, display ###-##-### and select it (see screen shot above)
The SSN may be entered with or without -'s. If entered without -'s redisplay it with -'s
If a SSN is entered with invalid data or is less than nine digits, display an error box (see above)


- Inquiry form The only active component is the Return button
If the crew member is not found, display an error box (see above)
- Change form Any/all fields can be changed except the SSN
When displayed, select the crew member's name
If the crew member is not found, display an error box (see above)
- Delete form Only the Delete and Cancel buttons are active
If the crew member is not found, display an error box (see above)
- Addition form All fields must be entered
If the crew member is already in the table, display an error box (see above)
The application consists of separate .java files: Menu, Inquiry, Addition, Change, Delete, and GetConnection.
// connect to an access data base // accepts the data base name as input and returns the Connection object
import java.sql.*;
public class GetConnection { private static Connection conn; // the connection object
public static Connection doIt( String dataBaseName ) { // create the driver object
// then connect to the database, allocate/create the connection (conn) object
// using dataBaseName as the database name try { Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
conn=DriverManager.getConnection( "jdbc:odbc:" + dataBaseName, "", "" ); } catch ( ClassNotFoundException e ) { System.out.println( "classname not found '" + e.getMessage() + "'" ); System.exit(0); } catch (SQLException exc) { System.out.println( "connect failed in GETCONNECTION: '" + exc.getMessage() + "'" ); System.exit(0); } // System.out.println("conected OK in GETCONNECTION"); // for debugging trace return conn; } // end of doIt method } // end of GetConnection class
|
How to call the method doIt():
public class xxxxx extends javax.swing.JFrame { private static Connection conn; // define the connection object private static Statement stmt; // the statement object private static ResultSet rs; // the ResultSet object
private boolean NotFound; private String work;
// Creates new form InquireForm public InquireForm(String SSN) { try { jbInit(); // builds form } catch(Exception e) { e.printStackTrace(); } work = SSN.substring(0, 3) + '-' + SSN.substring(3, 5) + '-' +
SSN.substring(5, 9); tryConn(SSN); if ( NotFound == true ) { dispose(); return; } . . txtZip.transferFocus(); } // end of InquireForm()
public void tryConn( String inqKey ) { // SSN passed to method as a nine digit String
conn = GetConnection.doIt( "JAVA01" ); // pass database name to doIt method
// run the createStatement method for your connection object try { // System.out.println( "create statement in INQUIRE" ); // for debugging trace stmt = conn.createStatement(); } catch (SQLException exc) { System.out.println( "query failed in INQUIRE with: '" + exc.getMessage() + "'" ); System.exit(0); } // create the SQL statement as a String (inqKey was passed to the constructor as a String) String stmtSource = "SELECT * FROM JTable01 WHERE SocialSecurity = '" + inqKey + "'"; // execute the SQL statement, the results (record) goes into the ResultSet object try { rs = stmt.executeQuery( stmtSource ); } catch (SQLException exc) { System.out.println( "query failed in INQUIRE with: '" + exc.getMessage() + "'" ); System.exit(0); } // System.out.println("query results in INQUIRE:"); // for debugging trace try { // get the record and put the data in the form's text boxes if ( rs.next() ) { // System.out.println("read in INQUIRE - found "); // for debugging trace aaaa.setText( rs.getString(2) ); // social security number bbbb.setText( rs.getString(3) ); // crew member's name . . NotFound = false; } else { JOptionPane.showMessageDialog( null, "SSN: " + inqKey + " not found...", "Error", JOptionPane.ERROR_MESSAGE); // System.out.println("read in INQUIRE - not found "); // for debugging trace NotFound = true; } rs.close(); stmt.close(); } // end try catch (SQLException exc) { System.out.println( "query failed in INQUIRE with: '" + exc.getMessage() + "'" ); System.exit(0); } // System.out.println( "query done in INQUIRE" ); // for debugging trace } // end of tryConn } // end of xxxxx
class
|