Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By bankTechy

Thread: inserting into multiple tables mysql using java

  1. #1
    bankTechy is offline Member
    Join Date
    Sep 2013
    Posts
    7
    Rep Power
    0

    Default inserting into multiple tables mysql using java

    Am trying to insert into multiple table simultaneously but it gives me errors. Any help resolving this will be appreciated



    try{
    String sql = "Insert into asset_update (Date_Acquired,Item_Code,Serial_Number,Cost_Of_Acq uisition,Estimated_Useful_Life,Depreciation_Start_ Date,User,Status,Disposal_Date)values (?,?,?,?,?,?,?,?,?)";
    pst=conn.prepareStatement(sql);
    pst.setString(1, ((JTextField)date_aquired.getDateEditor().getUiCom ponent()).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().getUiCompone nt()).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().getUiComponen t()).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_Me thod)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);
    }
    }

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,083
    Rep Power
    4

    Default Re: inserting into multiple tables mysql using java

    Broken record mode on: what error?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default Re: inserting into multiple tables mysql using java

    So that people do not have to repeat themselves, it is also asked here.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: inserting into multiple tables mysql using java

    And please post your code in [code] tags [/code]. Unformatted code is hard to read.
    Please do not ask for code as refusal often offends.

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,083
    Rep Power
    4

    Default Re: inserting into multiple tables mysql using java

    Ugh. I have lost all interest in this thread now.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    bankTechy is offline Member
    Join Date
    Sep 2013
    Posts
    7
    Rep Power
    0

    Default Re: inserting into multiple tables mysql using java

    i have been able to solve the problem. thanks y'all
    victor1 likes this.

Similar Threads

  1. Replies: 1
    Last Post: 04-23-2013, 12:50 PM
  2. Replies: 3
    Last Post: 10-18-2012, 03:00 PM
  3. Issues populating MySQL tables
    By Randy_Dennis in forum JDBC
    Replies: 2
    Last Post: 01-12-2011, 08:49 AM
  4. XSD Schema to MySql Tables
    By shellrandhawa in forum XML
    Replies: 0
    Last Post: 09-27-2010, 02:49 AM
  5. Replies: 0
    Last Post: 12-24-2007, 09:47 AM

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
  •