Hello. In this video, you will learn how to
use Java JDBC to update data in 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, please look at my other video,
Connecting To MYSQL Databases with Java. In this example, we will use the Employees
table. This table has columns for employee ID, last name, first name and email address.
Let’s switch over to the MYSQL tool, so we can take a look at some of the data. Here’s our sample table that we have with
sample data already in place. What I’d like for you to do is make note of David Brown’s
email address. He is currently listed as [email protected] We’re going to change this email address to
make use of luv2code.com. His new email address is [email protected]
The following sql can perform this update. We will use this sql update statement in a
Java application. This slide outlines our Java development process.
First, we will get a connection to the database. Then we will create a statement. Finally,
we will execute the sql update statement. Let’s move onto our development environment
and get started. We’re going to start with a simple Java program. The program is going
to start out with the url, the connection to the database, the user ID and password. The first thing that we’ll do is we will get
a connection to the database. Then we will create a statement. Then we’ll actually execute
the sql query. This is the same query that we had from the previous slide. Then we’ll actually do an execute update.
This will actually send the query to the database and perform the update. Finally, just to give
us some debugging information, we’ll have a print-line statement to say update complete. Let’s go ahead and run this application. Run
as Java application. It says update complete. Great. Let’s go to our SQL tool to verify
the results. In the SQL tool, I just simply do a refresh
and note the new email address for David Brown. It’s now [email protected] That works out,
and we’re actually successful with updating data using Java JDBC. This wraps up the presentation. If you’d like
to download the source code, please visit the website luv2code.com.