Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8951405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:39:20+00:00 2026-06-15T13:39:20+00:00

I’m trying to save or delete info type into this table to the database.

  • 0

I’m trying to save or delete info type into this table to the database. When I run this code I just keep getting the error and I can’t for the life of me figure out what I’ve done wrong. The frame opens and when you put in the ID as specified by the code corresponding with what you want to change it still isn’t changing.

import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;

class Changeadd {
JFrame f;
JPanel p1, p2, p3;
JTabbedPane tp;
ImageIcon btnimg1, btnimg2;
JLabel l1, l2, l3, l4, l5, l6, l7, l8, l9, l10;
JTextField tf1, tf2, tf3, tf4, tf5, tf6, tf7, tf8, tf9, tf10;
JScrollPane sp1;
JButton savebtn, resetbtn, editbtn1, editbtn2, deletebtn;

Changeadd() {
    f = new JFrame("Form");
    p1 = new JPanel(new GridLayout(5, 2));
    p2 = new JPanel(new GridLayout(5, 2));
    p3 = new JPanel(new GridLayout(2, 2));
    tp = new JTabbedPane();
    l1 = new JLabel("MenuID");
    l2 = new JLabel("Name");
    l3 = new JLabel("Info");
    l4 = new JLabel("Price");
    l5 = new JLabel("Enter Menu ID to delete");

    l7 = new JLabel("MenuID");
    l8 = new JLabel("Name");
    l9 = new JLabel("Info");
    l10 = new JLabel("Price");
    tf1 = new JTextField(12);
    tf2 = new JTextField(12);
    tf3 = new JTextField(12);
    tf4 = new JTextField(12);
    tf5 = new JTextField(12);
    tf6 = new JTextField(12);
    tf7 = new JTextField(12);
    tf8 = new JTextField(12);
    tf9 = new JTextField(12);
    tf10 = new JTextField(12);
    savebtn = new JButton(" Add ");
    resetbtn = new JButton(" Reset");
    editbtn1 = new JButton(" Edit ");
    editbtn2 = new JButton(" Save");
    deletebtn = new JButton("Delete");
    p1.add(l1);
    p1.add(tf1);
    p1.add(l2);
    p1.add(tf2);
    p1.add(l3);
    p1.add(tf3);
    p1.add(l4);
    p1.add(tf4);
    p1.add(savebtn);
    p1.add(resetbtn);

    p2.add(l7);
    p2.add(tf7);
    p2.add(l8);
    p2.add(tf8);
    p2.add(l9);
    p2.add(tf9);
    p2.add(l10);
    p2.add(tf10);
    p2.add(editbtn1);
    p2.add(editbtn2);

    p3.add(l5);
    p3.add(tf5);
    p3.add(deletebtn);
    resetbtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            tf1.setText("");
            tf2.setText("");
            tf3.setText("");
            tf4.setText("");
        }
    });
    savebtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            String value1 = tf1.getText();
            String value2 = tf2.getText();
            String value3 = tf3.getText();
            String value4 = tf4.getText();
            Connection con = null;
            String url = "jdbc:mysql://localhost:3306/mydb";
            String db = "myDB";
            String driver = "com.mysql.jdbc.Driver";
            String user = "root";
            String pass = "root";
            System.out.println(value1 + value2 + value3 + value4);
            try {
                Class.forName(driver);
                con = DriverManager.getConnection(url + db, user, pass);
                PreparedStatement st = con
                        .prepareStatement("INSERT INTO menu(menu.menuID,menu.name,menu.info,menu.price) values(?,?,?,?)");
                st.setString(1, value1);
                st.setString(2, value2);
                st.setString(3, value3);
                st.setString(4, value4);
                st.executeUpdate();
                JOptionPane.showMessageDialog(p1,
                        "Data is successfully inserted into database.");
                con.close();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(p1,
                        "Error in submitting data!");
            }
        }
    });

    deletebtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {

            String value1 = tf5.getText();
            Connection con = null;
            String url = "jdbc:mysql://localhost:3306/mydb";
            String db = "myDB";
            String driver = "com.mysql.jdbc.Driver";
            String user = "root";
            String pass = "root";
            try {
                Class.forName(driver);
                con = DriverManager.getConnection(url + db, user, pass);
                PreparedStatement st = con
                        .prepareStatement("DELETE FROM menu WHERE menu.menuID = ?");
                st.setString(1, value1);
                st.executeUpdate();
                JOptionPane.showMessageDialog(p3,
                        "Record is deleted successfully.");
                con.close();
            } catch (Exception exp3) {
                JOptionPane.showMessageDialog(p3,
                        "Error in deleting record.");
            }
        }
    });
    editbtn1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {

            String value = tf7.getText();
            Connection con = null;
            String url = "jdbc:mysql://localhost:3306/mydb";
            String db = "myDB";
            String driver = "com.mysql.jdbc.Driver";
            String user = "root";
            String pass = "root";
            try {
                Class.forName(driver);
                con = DriverManager.getConnection(url + db, user, pass);
                PreparedStatement st = con
                        .prepareStatement("SELECT FROM menu WHERE menu.menuID=?");
                st.setString(1, value);
                ResultSet res = st.executeQuery();
                res.next();
                tf7.setText(Integer.toString(res.getInt(1)));
                tf8.setText(res.getString(2));
                tf9.setText(res.getString(3));
                tf10.setText(Integer.toString(res.getInt(4)));
                con.close();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(p2, "Can not edit data");
            }
        }
    });
    editbtn2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            Connection con = null;
            String url = "jdbc:mysql://localhost:3306/mydb";
            String db = "myDB";
            String driver = "com.mysql.jdbc.Driver";
            String user = "root";
            String pass = "root";
            try {
                int x = JOptionPane.showConfirmDialog(p2,
                        "Confirm edit? All data will be replaced");
                if (x == 0) {
                    try {
                        String value1 = tf7.getText();
                        String value2 = tf8.getText();
                        String value3 = tf9.getText();
                        String value4 = tf10.getText();

                        Class.forName(driver);
                        con = DriverManager.getConnection(url + db, user,
                                pass);
                        ;
                        Statement st = con.createStatement();
                        st.executeUpdate("UPDATE menu set menu.name'"
                                + value2 + "', menu.info'" + value3
                                + "', menu.price'" + value4
                                + "' where menu.menuID='" + value1 + "'");
                        JOptionPane.showMessageDialog(p2,
                                "Updated successfully");
                        con.close();
                    } catch (Exception ex) {
                        JOptionPane.showMessageDialog(p2,
                                "Error in updating edit fields");
                    }
                }
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(p2, "Error");
            }
        }
    });
}

void dis() {
    f.getContentPane().add(tp);
    tp.addTab("Add Record", p1);
    tp.addTab("Edit Record", p2);
    tp.addTab("Delete Record", p3);

    f.setSize(350, 180);
    f.setVisible(true);
    f.setResizable(true);
}

public static void main(String z[]) {
    Changeadd pro = new Changeadd();
    pro.dis();
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:39:22+00:00Added an answer on June 15, 2026 at 1:39 pm

    I think your url is wrong

    String url = "jdbc:mysql://localhost:3306/mydb";
    

    already contains mydb appended

    con = DriverManager.getConnection(url + db, user, pass);
    

    will pass

    "jdbc:mysql://localhost:3306/mydbmyDB"
    

    also

    You have to put mysql-connector-java-5.1.18-bin.jar file inside the folder:

    YOUR_WEBAPPS_FOLDER/YOUR_WEBAPP/WEB-INF/lib/
    

    so that it will be available in the classpath when your servlet is compiled by the web container.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Let's say I'm outputting a post title and in our database, it's Hello Y’all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.