Good morning forum.
I have only been coding java for 2 weeks and have been given an assignment to create UML diagrams and a basic bit of programming in order to create a Fault Reporting Desk / Service desk.
Many of my friends have decided to stick to simplistic multidimensional arrays but to be different and challenge myself i have used MS Access via java.
I have created and populated all the fields of my database and including some constructors to add sample data/faults however i am stuck whilst trying to create a method that can select particular records and possibly update them by selecting a 'FaultNumber' that is an autonumber in my database.
public void updateAssignedengineer(String FaultNumber, String NewEngineer) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:ServiceDeskDB.mdb"); Statement stmt = con.createStatement(); stmt.execute("UPDATE ClassNetStore SET AssignedEngineer='" + NewEngineer + "' WHERE FaultNo ='" + FaultNumber + "'"); } catch (Exception err) { System.out.println("ERROR: " + err); } }
The above code is supposed to update a column called AssignedEngineer with the argument NewEngineer when the fault number which is to be updated is entered.
The autonumber FaultNo is a 'number' however in access it appears as 'autonumber' as it was created using"(FaultNo AUTOINCREMENT NOT NULL PRIMARY KEY")
If i select FaultNumber in my method signature as a primitive type 'int' the code fails to run. I have had to change my database autonumber field to be of TEXT type and change the method signature for the FaultNumber to String. This works however defeats the benefit of my autonumber which creates the fault numbers.
Is there a java type that is compatible with Access autonumber type or is there another method for achieving this please.
Any response is greatly appreciated.
My desired outcome would be to be able to achieve: ---------------V
Access DB Contents = FaultNo (type autonumber) Description (text), AssignedEngineer (String)
2424 Broken PSU John
create a code that could update AssignedEngineer to Bill when Fault No = 2424 but both the name and the fault number have to be requested by the user when the method is run.
Thank you very very much