 the mistake of using them in a different way. So if you want to update, use execute update and put the query. And if you want to get data, execute the query. The difference is that when you want to get data, you get the data in a Java data structure. So this data structure, its class is called result set. So you have to declare this. And you will get all the data that satisfies your statement in this data structure. So what is the result set? So the result set object is a list of peoples that satisfy your query. It's a view of the database on your Java virtual machine. And it looks like the table, but just those rows that satisfy the query will have this end, you see? So if you design this query, let's select all rows from flight's table where arriving is charge the code, airport in Paris. You will get this view of the database in the result set object, right? So we have this object, but we want to exploit this data. We want to do something with this data. We want to put it on a screen. We want to change the identification number. We want to put new departure time. So how shall we proceed? So result set has a method called next. What it does, this is a pointer to each row of the table to have retrieved. So we normally will put it on an iteration because the result of applying this method is a Boolean value. So it will give us a true value while the pointer shows to some data. If the pointer that comes to the end of the rows will get true. So that would mean that we don't have more data to process. So in the beginning, when you get the result set and you do for the first time R as next, your pointer is 0. But once you do once, it goes to the first one, and you will be able to get the attributes, the columns, on this row. So every time we do R next, we go to the next row, next row, next row. And so on until R as next is out of the bounds and it will give false Boolean value, right? So once we have the pointer in a determined row, we don't want to get the whole row, but maybe we want to get some specific files. We want to get the ID number of these flights to parries. And we want to get the departure time. We don't care about the arrival time. So the result set object has some methods that allow us to retrieve this specific piece of data. So if we want to get the flight ID, and we know that in the database, this is the third as an string, we just say, okay, in this R as object, let's get the string, and its attribute name is flight ID. And you will get this value here and the departure time here. And this for each row, while you iterate. So let's see how this came works. For example, go back to the database project, take down the update, and the result, information retrieval. So I have this sentence, it's the same as the one seen on this slide. I made use of the classes and the methods I mentioned, and what I do once I retrieve the attributes I want from each row, each row. I just print on the screen that flight, flight from Manchester to Paris, departure time, and they have this flight input, right? So I save, I execute. So this is the result we get. So flights from Manchester to Paris, departure time, seven, flight code, and this is what we get all the time this. So we've made the connection, we got the pointer to the database, we got the data. And now, if you are working with a server, what you can do is to embed this data within HTML tags, and this is what you get on the screen as a user. So, okay, we are at the end of the life cycle. We have connected, we have tried to update the database. We have retrieved the data, and now we're going to disconnect. We are done with our application. So it's easy to see. Just in the object, connection we have to clear. Just close the connection, we are done. So don't forget, because for clarity reasons, I removed here error handling sentences, but do not forget, obviously, otherwise you will not be able to compile your code, right? So for connection update, retrieval, and disconnection sentences, always try to catch the SQL exception, because there might be some problems in the SQL sentences, right? There's the general exception for looking up for the driver. And this is it. So far, we have designed this for atomic methods to access the databases. They're very basic, but it's the ones that do something with your data. The thing is that Java and JDBC belong to the object-oriented paradigm. For the sake of, let's do the things in the right way. Let's be good engineers. Let's apply the same patterns. Let's do the things in the right way so that the code is efficient and works perfectly, and it can be checked and it can be updated. So when we encapsulate these methods in a class, I make it independent of the application. So regardless what kind of data do you want to update, what kind of data would you want to retrieve from the database? Let's keep it simple and put these basic methods within a static class so that other classes can make use of it and how it looks like. Just the methods. I've shown you so far, but these are independent of the host, of the port, of the user, of the database name. So if there's a class calling to these methods, this class should make use of these methods using each specific requirement for the host, for the port, for the team user, for the query to update the database and for the query to retrieve. So this is a very simple class that allows you to access from any application to Java. So as I mentioned, we have this static class that encapsulates these basic accessing methods and we will have some other classes that make use of each one. So the goal when we design in such a way is to disclose the complexity, to heighten the complexity. So we could put all the source calls right in here. These examples I showed you, it's all in one class. So this works, you've seen that this works, but come on, let's be elegant, let's do it in the right way, right? Last over engineers. So there will be some other classes that will define the queries and will define how to retrieve the data from the database. So in this application, you have an airport that connects to the database manager. And the database manager has some methods implemented. You can get the list of the flights, you can add a delay if you have the code of the flight, you can add a new destination in the database, you can update the arrival time and so on. But you never change this, right? The only thing you change is the database manager, which is the class in between the main class and these basic methods, right? So how does the database manager look like? So this is up to you. I mean, depending on the requirements in your application, the database manager will define different methods. But we want to get the list of flights, I want to add a delay. For instance, so how we deal with this status class? So first of all, we have to define, we have to import the class, hit a reference to it, and then it's just that easy. We have to connect, giving the proper host or user password according to our requirements, and then we will retrieve according to the x square sentence we defined, and then we'll disconnect, we connect, update, disconnect, no matter which method we are designing, we always make use of these three classes. Don't forget about the rest, yeah? So let's see how this can be seen in a real-world project. So as opposed to this long piece of code, and it's the same application following this parameter. So we have the main class. Look what simple it is. Just main class that we call to the database manager. The database manager is a couple of methods that we do, that we deal with the database, and we make use of this basic accessing method, which is retrieve, update, disconnect. So in this way, this goes in line with what Caroline mentioned this morning, is our description of concern. Let the database handle it on one side, and let's exploit the data from the database on the other side, which will be done by the database manager. What we do here is, okay, we are making use of the database manager, and we want to get the list of slides that go to Charles de Gaulle Paris. So we make use of the list of slides. To put the rival code in the main class, let's see how it works. But instead of having one class, we have three different classes. The modularity of the whole system is high. And so let's see what are the benefits of using this way of design. So reusability is boosted, because this class that makes use of the basic atomic sentences, you don't have to touch it. You don't have to touch it at this moment. So this example I've shown you, I just copied this from my software engineering classes when I took the class in 2004. I've been making use of it since 2004. It's been eight years making use of this. I didn't change it at all, and I've been developing Java programs eight years. So make sure you make a good one and keep it in your pocket, yeah? Because it's not easy. Yeah? So complexity is given. You have three different classes, but the concerns are separated. The code is way cleaner. You don't have to know this spaghetti code. The whole stack in one class. And it's very difficult to get to them separately. Of course, if we follow the object oriented paradigm, we get higher modularity and by far it has a greater maintenance. You can make updates more easily, so on. So all the examples we've seen here are stored in my local machine and don't make use of the network. Because my database was hosted in your local host. But what's the role of JTBC and database access in this class of web applications? So this pattern keeps the same. The only thing that changes is that the main class is a servlet now. So it inherits all the methods of the server, which is the init method, the destroy method, and they do get it. But in the end, the backbone is still the same. So no matter if you are using a web application, you are using an applet, you are using a servlet, it's not the same. The only thing that changes is that, okay, now we can play around with a web server. I will have some data from the database. We can put it on HTML and show it. And of course it's more interactive and more easy to use for the user. And it's all reachable because we all have the universal client, which is the process of developing the application, you know. And since it is Java, you can use it in any machine. So there, as mentioned, and coming back to the example I tried to explain in the beginning, you can retrieve the data and put this data on the template. Or if you want to book a flight, put the data regarding flights onto the templates in the servlet. I just want to finish. I want to let you know that this is a very widespread example. These days, databases or web applications, by definition, are not established anymore. And they make heavy use of databases. They heavily rely on databases. So this is something you have to keep in mind. And please try to make use of these good practices and keep this class for you. Because it will be very useful for you in the future if you are developing Java applications. For the class, for the lab in this afternoon, we are not following this design pattern for the sake of simplicity and because maybe some of you are not familiar with the problem. But still, some of you don't. You can still try to do it. You will get higher marks, probably. Yeah, so this is it. If you have any questions, please feel free to answer me. Thank you very much. Excellent. Thank you very much.