Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Creating a method argument that uses access database autonumber! Help!!

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Creating a method argument that uses access database autonumber! Help!!

    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


  2. #2
    Member
    Join Date
    Dec 2011
    Posts
    50
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: Creating a method argument that uses access database autonumber! Help!!

    The code fails to run because the primary column (plus auto number) cannot be updated. Remove the autonumber property then it will work.

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Creating a method argument that uses access database autonumber! Help!!

    I am hoping to use the autonumber function as this is creating a unique fault number for each record. Thankyou though.

Similar Threads

  1. How to remove argument from abstract method.
    By jainshasha in forum Object Oriented Programming
    Replies: 12
    Last Post: June 30th, 2011, 10:33 PM
  2. [SOLVED] Send File (path) as argument to method
    By efluvio in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 31st, 2011, 01:13 PM
  3. Database access..
    By _lithium_ in forum JDBC & Databases
    Replies: 7
    Last Post: March 2nd, 2011, 10:32 PM
  4. Access database SQL query help
    By mjpam in forum JDBC & Databases
    Replies: 3
    Last Post: September 8th, 2010, 08:48 AM
  5. Generic method using an int[] argument
    By dubois.ford in forum Collections and Generics
    Replies: 2
    Last Post: March 18th, 2010, 07:18 AM