dcsimg
www.webdeveloper.com
Results 1 to 11 of 11

Thread: Swing

  1. #1
    Join Date
    Nov 2004
    Location
    London
    Posts
    6

    Swing

    Hi, Can anyone help me. I am trying to insert, update and delete a record from an Access database using swing. The GUI has been created and the connection to the database established. After entering the record on the screen and pressing the save button, I am unable to insert. Also my combo box doesn't retrieve records into the appropriate fields on the screen. In-fact it doesn't retrieve the records from the database at all. sample codes to help me will be highly appreciated.

    I know I am doing a few things wrong because I am new to Java but I am learning quickly.

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,137
    post your code here or better yet zip all of your code/project and upload it to this thread...(including the access db if its not too long)
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  3. #3
    Join Date
    Nov 2004
    Location
    London
    Posts
    6
    Thank you, here is the code. The code will create the db when its run. If you require more information please drop me a mail at umoetuk@btinternet.com

  4. #4
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,137
    Originally posted by Olodu
    Thank you, here is the code. [/email]
    .


    ok pardon my blindness...:-)
    but where is the code.....
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  5. #5
    Join Date
    Jul 2004
    Location
    West Coast, Canada
    Posts
    665
    lol.

    Yeah, I'd like to help try and figure it out too because I haven't tried doing any database work with Java yet. This will help me learn a lot more.

  6. #6
    Join Date
    Nov 2004
    Location
    London
    Posts
    6

    Red face

    Hi,

    I am sorry, I do not understand how the thread works. I have attached a zip file with these threads I am sending but I can't seem to find it on the screen after it had been sent. I don't know what I am doing wrong. The code is quite long hence I cannot paste it in the thread. Can I send it to your e-mail address? If yes, please send me your e-mail address.

    Regards
    Michael

  7. #7
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,137
    this is how you attache file
    1, click on the "post reply" button
    2. then scroll down and look towards the left of the page you will find
    a button with caption "browse" and right underneath there are formata
    allowed to be uploaded(e.g gif,zip etc)
    thats it when you submit reply then it should be uploaded...
    every users email adress can be found from that users profile...
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  8. #8
    Join Date
    Nov 2004
    Location
    London
    Posts
    6
    Hi,

    I have tried attaching the file but it just won't go I guess I just won't be able to send you the complete file. I will send just the bit I am having problems with.

    public void insertRecord()
    {
    try {
    Connection con = DriverManager.getConnection("jdbcdbc:toy");
    System.out.println("Connection Opened...");
    Statement stmt = con.createStatement();

    String txtcopies = copies.getText();
    String txttitle = title.getText();
    String txtauthor = author.getText();
    String txtpub = pub.getText();
    String txtyear = year.getText();
    String txtisbn = isbn.getText();
    String txtcategory = category.getText();
    String txtprice = price.getText();
    stmt.executeUpdate("INSERT INTO Books_in_stock " + " VALUES ('" + txtcopies + "', '" + txttitle + "', '" + txtauthor + "', 'txtpub', 'txtisbn', 'txtyear', 'txtcategory', 'txtprice')");
    JOptionPane.showMessageDialog(apanel, "Record Inserted");
    con.close();
    }
    catch (Exception e) {
    JOptionPane.showMessageDialog(apanel, "Insert Error, Cannot insert data...");


    }

    }

    }

    The problem is that the code inserts the record as a string literal and not as variables entered on the Swing screen.

    Cheers
    Michael

  9. #9
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,137
    values in bold will be entered as litterals and will not be used as variables
    stmt.executeUpdate("INSERT INTO Books_in_stock " + " VALUES ('" + txtcopies + "', '" + txttitle + "', '" + txtauthor + "', 'txtpub', 'txtisbn', 'txtyear', 'txtcategory', 'txtprice')");

    if you want them to be entered as variables then you will need to use proper string cancatenation format for variables
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  10. #10
    Join Date
    Nov 2004
    Location
    London
    Posts
    6
    Hi Khalid,

    I delibrately left the values in bold without the double qoutation marks as I was testing which values are stored. The first couple of variables (i.e. txtcopies, txttitle, txtauthor) are left blank in the database while the ones in bold are inserted as string literals i.e. txtpub, txtisbn, txtyear e.t.c.

    I believe for some reasons, the values entered on the screen are not been retrieved by the getText method. The JTextFields have been declared i.e. copies, author, year, isbn e.t.c and as you can see from the code I sent to you, I have also used the getText method to retrieve these values. The records are been inserted but as string literals. The ones passed in as variables are left blank in the database.

    Regards
    Michael

  11. #11
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,137
    As I said before I need to the full code to see in action,however from what you said could it not mean that your variables are empty? that is they do not have any values in them?(you can email me the whole project in a zip file....
    I'll find some time in next few days the run your project...

    k_ali at shaw.ca
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles