current position:Home>JDBC connects to the database for data deletion. The syntax is correct, but the data in the database cannot be deleted
JDBC connects to the database for data deletion. The syntax is correct, but the data in the database cannot be deleted
2022-02-03 00:57:21 【CSDN Q & A】
The phenomenon and background of the problem
Problem related code , Do not paste screenshots
public void del_stu() { JFrame jf = new JFrame(" Dormitory information deletion ------>"); JLabel jl1 = new JLabel(" The student's name :"); JTextField jt1 = new JTextField("",10); JLabel jl2 = new JLabel(" Student student id :"); JTextField jt2 = new JTextField("",15); JButton jb1 = new JButton(" Delete "); jf.setLayout(new FlowLayout(FlowLayout.CENTER)); String stuname = jt1.getText(); String stuid = jt2.getText(); jb1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Class.forName("com.mysql.cj.jdbc.Driver");// load mysql drive String URL = "jdbc:mysql://localhost:3306/dor_information?&useSSL=false&serverTimezone=UTC&serverTimezone=GMT%2B8"; Connection connection = Connect.getConnection(); Statement statement = connection.createStatement(); String sql = "delete from dor_stu where Student number =? "; PreparedStatement pstmt = connection.prepareStatement(sql); pstmt.setString(1, stuid); pstmt.executeUpdate(); ResultSet rs = statement.executeQuery("select *from dor_stu"); while(rs.next()) { if(!rs.getString(2).equals(stuid)) { System.out.println(" Delete successful "); } } }catch(Exception e1) { e1.printStackTrace(); } } });
Operation results and error reporting contents
What is reported here is that the deletion is successful
My solution ideas and tried methods
What I want to achieve
The database can delete the data
1.
Refer to the answer 1:
JDBC Operating database instances _Stay Hungry-CSDN Blog _jdbc Operating the database
It's using Statement.execut(sql)
Refer to the answer 2:
Refer to the answer 3:
Execute deleted sql After need commit Commit transaction
Refer to the answer 4:
copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202030057193910.html
The sidebar is recommended
- MySQL reports an error in Navicat. How to solve it?
- Router link cannot jump into router view (Vue)
- Why is the camera preview frame obtained by Android like this
- How to implement JS? The address bar changes the page load and refresh, and the selected conditions of the current page remain unchanged as all by default
- Why did 0.3 become 0.2999999999
- What is the reason for the warning when Vue project is packaged
- Yolov5 deployment final inference report cannot find picture
- How to extract the characters of a paragraph in Notepad?
- Computer network technology IP questions
- MySQL group query gets the data of the first 24 hours in each group
guess what you like
-
What's wrong with this and need to be changed?
-
Write a program to find the number of integers between 200 and 300 that meet the following conditions. Condition: the product of hundreds, tens and individuals is equal to the sum of hundreds, tens and individuals
-
In Python, the condition setting and interpretation of while loop
-
How can jupyter notebook run on the next line of code followed by the above code
-
The page has been loaded. Press F12 at the top to show it. What's going on
-
This CompareTo method is not called. How do you sort the elements in the collection
-
Using pointer method: input three integers ABC and output them in order of size
-
C # new ADO Net data model, error, failed to load file or assembly
-
Input n integers from the keyboard and store them in a pile of arrays. Put all positive numbers in the array in front of the array and negative numbers in the back to output the array
-
Why can't the small gourd be installed.
Random recommended
- Java byte array and string conversion
- Definition of two-dimensional array in C language
- Why is there an extra 0 here?
- Python code programs don't
- Measure the distance with sound wave, and then send the result to the serial port. Do you want to interrupt twice, language interrupt, and ask for an idea
- An error occurs when starting Hadoop. How to solve it?
- What about the problem of remote access server?
- pywintypes. com_ Error: (- 2147023728, 'element not found', none, none)
- Global variables don't work in this program? Why is the answer a
- In Python, there is something wrong with the program and an error is reported
- Simple OJ questions for Freshmen
- Butterfly effect problem, insufficient number of input parameters
- Use of extractall function of Python zipfile module
- After spring imports the database and c3p0 dependency package in idea, it will prompt the database for abnormal error
- Python from introduction to practice 5-10
- 1703792 what does that mean? What's wrong?
- C language and C + are easy to search dogs
- This interface is always used when I use CONDA to install tensorflow? About half an hour. How?
- React summernote rich text editor!! Why do some function icons of rich text editor fail after I pack them
- How does silly girl robot log in with mobile phone
- Why can't I see the absolute path of the command
- Pycharm uses the requests crawler to report the wrong requests exceptions. SSLError: HTTPSConnectionPool
- How to run multiple sleep () simultaneously in C language
- The data requested by Axios in vue3 is put into ecarts, which always shows that setoption is not defined
- What do these two for loops mean
- Java judges whether there are 30 consecutive int arrays with a length of 1000 as the growth trend
- Force deduction 221 question maximum square
- When I set this layout, I prompted an error from line 18
- The import javax. security. auth. message cannot be resolved
- The hottest Christmas tree code. one hundred and twenty-three
- Open the edge browser and display "what if I can't access this page?"?
- Running problems of java simple supermarket system
- Is the data [10] here an address or an element? The concept is always unclear
- Python crawling news content
- How to deal with the problem of general code framework
- Bubble sort, how can there be an extra number in front
- The graph drawing algorithm of Python is described by Raptor flow chart software
- Numpy creates an array of the specified data range
- Python crawler obtains the data of Douban movie top250 fantasy class
- R7-2 minimum spanning tree construction (25 points)