NEED TO LEARN JAVA - 5 FREE JAVA VIDEO COURSES - CLICK HERE - goo.gl/7i95F8
View more videos on my "Java JDBC Tutorial" Playlist: goo.gl/crT4nS
Closed-Captioning and English subtitles available.
In this video tutorial, you will learn how to delete data from a MySQL database using Java JDBC.
Download the source code from here:
Please subscribe to my channel. goo.gl/EV6Kwv
Join my mailing list: Get advance notice on new tutorials. Emails about 1 per week.
Questions or problems? Post them in the comments section below.
Want to suggest a video? Leave a comment below. I'm always looking for new video ideas.
Let me know what video you'd like for me to create.
Time - 00:00
Hello. In this video, you will learn how to use Java JDBC to delete data from a database. In regards to Prep Work, you must have a database installed. This demo will use MySQL.
You also need to have the database driver configured. Again, we’ll use MySQL. If you need help on how to do this, then please look at my other video “Connecting to a MySQL Database with Java.”
Time - 00:31
In this example, we will use the employees’ table. This table has columns for employee ID, last name, first name, and e-mail address. Let’s switch over to the MySQL tool so we can review the data.
Time - 00:45
As you can see, we have the employees’ table in place. Make note of the entry for David Brown. We will delete this employee from the database. The SQL command that we’ll use to delete an employee is delete from employees where last_name=’Brown’;
Time - 01:09
Let’s move and try development environment and get started. We’ll start with this main program, that’s going to have three variables for the user, password, and the connection information. The first thing we’ll do is we’ll get a connection to the database by saying DriverManager.getConnection, passing in the params. Next, we’ll create the statement using myConn.createStatement. Then we’ll define the SQL query string. In this case,
delete from employees where last_name=’Brown’
Time - 01:43
Now, actually execute that SQL statement by saying executeUpdate and the database will return the number of rows affected. Also, I will print those out. Then finally, I’ll just print out “Delete complete.” so that we know that I’m done.
Time - 02:01
Now, let’s run our application. I’ll right click; I’ll select “Run As”, “Java Application.” Now, let it execute. Now, it will print out the number of Rows affected and Delete complete. Now, let’s move over to our SQL Query tool and very the results.
Time - 02:24
If you note here with the previous entry, we had a listing for a David Brown. I’ll refresh this Query, and now note that David Brown is gone. A Java Application was actually successful in deleting that entry.
Time - 02:37
Great, so in summary, you learned how to use Java JDBC to delete data from a database. If you would like to download the source code, please visit luv2code.com