Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2013
    Location
    Accra,Ghana
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    am trying to insert into multiple tables in mysql using java

    try{
    String sql = "Insert into asset_update (Date_Acquired,Item_Code,Serial_Number,Cost_Of_Acquisition,Estimated_Useful_Life,Depreciation_Start_ Date,User,Status,Disposal_Date)values (?,?,?,?,?,?,?,?,?)";
    pst=conn.prepareStatement(sql);
    pst.setString(1, ((JTextField)date_aquired.getDateEditor().getUiComponent()).getText());
    String ItemCode = ComboBox_itemCode.getSelectedItem().toString();
    pst.setString(2, ItemCode );
    pst.setString(3, txt_sn.getText());
    pst.setString(4, txt_coa.getText());
    pst.setString(5, eul.getText());
    pst.setString(6, ((JTextField)date_dsd.getDateEditor().getUiComponent()).getText());
    String users = jComboBox_Users.getSelectedItem().toString();
    pst.setString(7, users);
    String status = ComboBox_status.getSelectedItem().toString();
    pst.setString(8, status);
    pst.setString(9, ((JTextField)date_dd.getDateEditor().getUiComponent()).getText());

    String branches ="insert into branches(Branch_Area)Values(?)";
    pst=conn.prepareStatement(branches);
    String barea = combo_Area.getSelectedItem().toString();
    pst.setString(1, barea);

    String items ="insert into items(Description,Description_Code,Depreciation_Method)Values(?,?,?)";
    pst=conn.prepareStatement(items);
    String decode = ComboBox_decCode.getSelectedItem().toString();
    pst.setString(1, decode);
    String depm = ComboBox_dm.getSelectedItem().toString();
    pst.setString(2, depm);
    pst.setString(3, txt_desc.getText());
    pst.execute();
    JOptionPane.showMessageDialog(null, "Saved");
    }
    catch(Exception e){
    JOptionPane.showMessageDialog(null,e);
    }
    }

    Am getting errors. any help with this code will be appreciated thank you.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Post the errors. Code is useless without a problem to compare it to.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Tags for this Thread

    Posting Permissions

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