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: Insert data from Jtextfiield into Mysql Workbench Database.

  1. #1
    Junior Member
    Join Date
    Aug 2022
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow Insert data from Jtextfiield into Mysql Workbench Database.

    Hello, I am a beginner in java programming and I have recently had difficulty saving my data entered from my Jtextfield into mysql database.

    This is my current code, it runs fine but I don't know what I need to add to save my data into mysql database.

    This is my current code for my main method class:
    public class Main{
     
        public static void main(String[] args) {
            new MyFrame();
        }
    }
    This is my current code for my main menu class:

     
    import javax.swing.*;
    import java.awt.*;
     
     
     
    public class MyFrame extends JFrame{
     
     
     
        JLabel label;
        JMenu Add;
        JMenu remove;
        JMenu items;
        JMenu vendors;
        JMenuBar menuBar;
        JMenuItem addCustomer;
        JMenuItem addVendors;
        JMenuItem addProducts;
        JMenuItem removeCustomer;
        JMenuItem removeProduct;
        JMenuItem removeVendor;
     
     
     
        MyFrame(){
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setLayout(new FlowLayout());
     
            label = new JLabel("Inventory Software");
            label.setFont(new Font("Comic Sans MS", Font.BOLD, 30));
     
            menuBar = new JMenuBar();
     
            Add = new JMenu("Add");
            remove = new JMenu("Remove");
            items = new JMenu("Items");
            vendors = new JMenu("Vendors");
     
     
            addCustomer = new JMenuItem("Add Customers");
            addVendors = new JMenuItem("Add Vendors");
            addProducts = new JMenuItem("Add Products");
     
            removeCustomer = new JMenuItem("Remove Customer");
            removeProduct = new JMenuItem("Remove Product");
            removeVendor = new JMenuItem("Remove Vendor");
     
     
            remove.add(removeCustomer);
            remove.add(removeProduct);
            remove.add(removeVendor);
     
            Add.add(addCustomer);
            Add.add(addProducts);
            Add.add(addVendors);
     
            menuBar.add(Add);
            menuBar.add(remove);
            menuBar.add(items);
            menuBar.add(vendors);
     
     
            addCustomer.addActionListener(new WindowAC());
            addVendors.addActionListener(new WindowAV());
            addProducts.addActionListener(new WindowAP());
            removeCustomer.addActionListener(new WindowRC());
            removeVendor.addActionListener(new WindowRV());
            removeProduct.addActionListener(new WindowRP());
     
     
            this.setPreferredSize(new Dimension(550, 300));
            this.setJMenuBar(menuBar);
            this.add(label);
            this.pack();
            this.setVisible(true);
            this.getContentPane().setBackground(Color.WHITE);
            this.setLocationRelativeTo(null);
            this.setTitle("Intact Communications Inventory Software");
        }
        }

    This is my current code for my add customer class:

     
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
    public class WindowAC implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
            if("Add Customers".equals(e.getActionCommand())){
     
                JFrame windowAC = new JFrame();
     
                JLabel label = new JLabel("Name:");
                JLabel label1 = new JLabel("Address:");
                JLabel label2 = new JLabel("Email:");
                JLabel label3 = new JLabel("Tel: ");
                JLabel label4 = new JLabel("FAX: ");
                JLabel label5 = new JLabel(" ");
     
     
                JTextField textField = new JTextField();
                JTextField textField1 = new JTextField();
                JTextField textField2 = new JTextField();
                JTextField textField3 = new JTextField();
                JTextField textField4 = new JTextField();
     
                JButton button = new JButton("Submit");
     
                label.setBounds(50, 100, 100, 50);
                label1.setBounds(50, 150, 100, 50);
                label2.setBounds(50, 200, 100, 50);
                label3.setBounds(50, 250, 100, 50);
                label4.setBounds(50, 300, 100, 50);
                label5.setBounds(50, 350, 100, 50);
     
     
     
                textField.setBounds(150, 110, 400, 30);
                textField1.setBounds(150, 160, 400, 30);
                textField2.setBounds(150, 210, 400, 30);
                textField3.setBounds(150, 260, 400, 30);
                textField4.setBounds(150, 310, 400, 30);
     
                button.setBounds(300, 450, 100, 70);
     
                windowAC.setSize(750,750);
                windowAC.getContentPane().setBackground(Color.WHITE);
                windowAC.setTitle("Add Customer info");
                windowAC.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                windowAC.setVisible(true);
                windowAC.setLocationRelativeTo(null);
     
                windowAC.add(button);
                windowAC.add(label);
                windowAC.add(textField);
                windowAC.add(label1);
                windowAC.add(textField1);
                windowAC.add(label2);
                windowAC.add(textField2);
                windowAC.add(label3);
                windowAC.add(textField3);
                windowAC.add(label4);
                windowAC.add(textField4);
                windowAC.add(label5);
     
            }
     
        }
     
    }

    I was hoping ya'll could help, been stuck on this problem for a very long time.
    Last edited by Uzair_Ahmad; August 22nd, 2022 at 09:27 PM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Insert data from Jtextfiield into Mysql Workbench Database.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Aug 2022
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Insert data from Jtextfiield into Mysql Workbench Database.

    Okay will do, thanks for letting me know.

Similar Threads

  1. How to insert data in MYSQL with jsp
    By blasic in forum JDBC & Databases
    Replies: 3
    Last Post: December 5th, 2013, 01:03 PM
  2. problem - insert negative value to mysql database.
    By vasanthjayaraman in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 12th, 2013, 09:45 AM
  3. Replies: 1
    Last Post: June 29th, 2012, 01:29 PM
  4. Replies: 1
    Last Post: April 9th, 2012, 05:13 PM