Java Servlet JSP JDBC CRUD | Insert Update Delete with Jakarta Servlet and Tomcat 10.x - Latest

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
orientation in this video you are going to learn how to perform current operation or create update delete or inside of the delete so in this complete project I am going to use circulate and JSP and jdbc and MySQL has a database in the backend so if I click on here add a course then you can see I will add here for example or react.js and then duration 6 month and category computer and course fee maybe 24 times so now if I add a question you can see this data is coming from database display now if I want to delete this then I can click here and successfully I can delete once again if I want to add here for example we'll start Java and then six months here computer and then 660 000 now if I want to update it then you can see the data is coming filled so I will write here that last Java and this 12 months and you say fiction and maybe thirty thousand okay the question and now add so guys you can see successfully it has been updated so this complete tutorial you will learn step by step so guys stay connected in the follow this video step back save so that you will know this latest Jakarta servlet and uh also a tomcat 10 X version I've used in this project so guys let's see step by step till end and then you will be able to learn how to perform instead of getting delete so let's first understand what is jdbc jdbc stands for Java type Wireless connectivity that means war suppose you have Java application in the website and database like MySQL Oracle SQL Server fibers or maybe any of the database okay so you want your Java applications to connect with database so it is not possible directly to connect with the database so what we need we need any third-party software which will help to connect Java applications to the database and this is called jdbc driver so this act as a bridge between Java application and any database like MySQL Oracle SQL Server Etc so that is the main task of jdbc we will be in this project we will be using this jdbc to connect our Java application to the MySQL server now let's see this important structure because understanding this will give you a clear picture that how this JSP and circulate work okay so first we are going to create database connection so that's called DB connect we will be creating a file where our database connection or jdbc connection will take place and the second one will be model where getter and seta that means whatever data will be a Fed will be inserted by user first it will be getting and setting so that what will be done inside the model okay and the third one is user Tau or we can call the database object so this section will take place inserting updating deleting this uh kind of task will be performed by Dao class okay and finally it will be servlet so so and this servlet will be handling the request of JSP so whenever any user insert any data then it will be handled first by servlet then servlet will be utilizing these three Java file so that is the main Java file structure in this project we will be creating these files later in this video and I will explain that how that works now let's understand that how this work suppose we will create here user.jsp this user.jsp will send the data to servlet and servlet will utilize user tab this Java file will require this database connection file and also model file so this is the flow of our code structure which we'll be using in our project so guys now let's get back to the Practical thing so we will start by implementing the concept that you have learned so far so guys we are going to do current operation or insert update delete and our project name will be this mini project name will be course manager where there will be course name course duration and course category so whatever name you will provide like you know Java or servlet PHP JSP etc etc and core City okay so we will be inserting this data through uh you know jdbc servlet into or MySQL server and this is our View files whatever data we will be inserting we will show here the list of the courses where there will be serial number name post name category duration fees as well as here the we can delete the list any individual record you can view and edit and update as well so we are going to perform the complete credit application or instead of the delete in this project so guys watch this video step by step so that you will understand that how you can perform this ask so let's start implementing this what we will do we will start a new project you guys these are the file structure which we will be using and I'll also upload this in GitHub so that you can directly download you don't have to write the code for this HTML you can use this in your project so I will open Eclipse IDE I'll be using this Eclipse ID for this project and we will create a new project called so we will create with Dynamic wave project okay and here we will name it as management course management okay and leave adaptable things as it is the click on next next and then click on this so that web.xml file will be generated and click on finish so we have created this project till now the next step what we will do right click on this and then go to configure and click on convert to Marvin project actually we are going to convert this to Mount Project so that all the dependency we will write here the code for that and directly it will download and keep into its Library file you don't have to manually download it okay so that's why we will be using this moment project so first thing we need to do dependencies right here dependencies okay inside this we will write our dependencies so let's go to the browser and find here Google Marvin repository okay let's go to its official website and then find here the first thing will be jdbc connector JD DC or MySQL connector you can see my SQL connector since we are going to use MySQL that's why so we see the file now click on this by the time this video is recorded you can see 8.0.32 each pair so click on this and simply just paste here that's it the next thing we which we will be requiring will be Jakarta servlet Jakarta okay so we need this API as well remember if it is previously it will use Java X servlet but now it is used so by the time this video is recorded I'm showing you the latest one okay so let's go here and click so with the data subject is also with here now we will write here Jakarta jstl this one okay this will be used for yeah GSP file JSP tagging okay so this is the third one and one more thing will be requiring class piece Jakarta so if you go back here and then you can see Jakarta standard tag Library implementation we will be using this one also so that's it guys in this project now click on this and it is copied successfully now paste here that's it so what happened actually whatever we need you can go to here this project and Java resources and then libraries so guys all these files got successfully downloaded here you can see so as per this project structure what we will do we will create these two four packages and inside those we will creating this file but before that let's create this JSP file called user.jsp where our end.hp whatever name you want to give it so that user can input the data so what we will do just copy this CSS and images just Ctrl C copy and then let's go here and then this RC Main and web app okay right click on web and paste so CSS in the image has been successfully copied here and paste it now the next will be right click on web app and then new and then JSP file okay so let's name it as ADD dot JSP so this will be our editing file not finished so let's do one thing let's go to this file and Index right so right click on this and let's open here in any text editor so just I'll copy it okay let's copying the whole thing and then I will paste here just removing this up to here okay so this is our address in the app.jsp a form so where the form is starting yeah form is starting here so inside form you will write here uh method method equal to post and xn equal to for the time being blank we will create our sublet and then we will name it in the meantime we would like to see if this Android JSP is opening prepared properly or not so run as run on server okay that in this click on this so guys I expect that you have already installed this Eclipse as well as Tomcat service so in case you have not installed this thing then I strongly recommend you that watch my previous video where I have shown how to install this Eclipse as well as how to install this Tomcat server okay so now just click on finish starting the server Tomcat server is one of the most popular server for creating JSP in this package so guys this is our course management item .jsp file that's right now let's create another file we will create here another file called hue present JSP U dot JSP this so inside this view.jsp now let's get back here and then right click on this and open the code Ctrl a Ctrl C that means copy and then now let's paste the whole thing here as well So currently these are static but at least we can see that okay these files are opening so right click once again on this and run on server so that we can see if this works perfectly or not of course these are static for the typing so we will be bringing all these things then let me step by step in this video so stay connected and watch the video properly now if you want then you can change the title here as well courses like this The Next Step guys we will be creating our Java files in the next chapter chapter we are going to create Java files okay okay so you can see here Java resources and this SRC main Java now right click on this and new and first we will create package okay so the first package name will be provide here will be t b connect okay or simply we can name it as DB so this is our first package the next package will be model okay so create here package called model and then inside model sorry once again we will create another one and that will be and that will be Tau file and finally we will create our servlet package that will be wave okay so we have created four one what we have already explained in or PPT file okay so guys now in DB file right click on this and let's create a class Java class and that will be DB connect the file name will be okay and then finally click on finish now we will write the code here for connecting our jdbc already we have if you check here inside library then you can see MySQL connector is already there so that it will be working as a jdbc connector okay so now start writing the code here if you go to the official MySQL website my list will jdbc connection okay if you check then you can see here so these are the method to which we can connect so we will be implementing this second one okay this one will create a function actually and then inside that we will be writing the code so the first thing will be connection connect none so let's import these things first because this will be the packages which will be requiring so right click on this actually it will be here in the top okay so import JavaScript and then here connection connection initial will be none connection okay so initial will be null here now we will create here one function and that function we will be calling in our draw file right here probably that key connection then get connection and here you see the function dimension study connection then get connection this is our function name or shall we return statement letter now in settings we will write Drive law and then of course will be catch block foreign catch inside Drive lock we will put this one this one okay but before that we need to call here class dot or name then insert this jdbc so it will be class dot or name then com dot mysql.cj.jdbc dot Drive okay and then connection refers to driver manager Dot jdbc Dot get connection get connection and inside this we will be writing this string for database connection okay insert this so connection driver manager manager captain driver manager so here as you can see jdbc colon MySQL localhost and then here will be the database name so we can name it as course correct and then username so in my case the username is my admin and then password is thing you'll learn 13. so guys while installing MySQL you might have provided username and password you need to provide username and password only you can write here root and password blank but if you have provided username and password in your MySQL server and also we need to specify here the port number so where we will get this port number if you you need to install MySQL as well so I expect that you have already installed this MySQL you know that how this my experience MySQL workbench works okay you can see here my port number is three zero zero eight but normally the port number is three zero zero six Okay so because of conflicting problem I have provided here different port number but in general 99.99 the chances is uh the port number will be three three zero six but in my case it is three three zero eight so we will provide three three zero eight this port number so with the error okay this is no no so this section we will be copying here and pasting insert inside our catch block okay and then we are creating errors what does it say okay change to static this will be static connection so this problem is gone and now it says throw exception that's fine class not found that's it so guys successfully we have created our this DB connection file okay later we will create this uh database as well okay guys so now we will be working on modules so let's see in the next chapter back to this chapter and we will be working on our model class okay so we will have problem Fields course name course duration category and course fee so now let's get back to here and okay so we will name it as you course we will name it as Force okay right so here we set this private uh course name so private then stream Oh and before that gets right here private uh course ID private int it will be int course ID and then host name Force category right it is duration so once again private string or int hint uh du position then drive it string private stream uh category okay so these are the power fields right now guys we will be generating getter and shutter for this okay so right click on this and click on source and then generate getter send status okay this one now select all and then generate so automatically this got generated this will be in the top apart from that we can also convert this into bootstring so once again go to source and then to string so in case you want to display the data then we can show here as a two string so that's it in this model for the time being now the next task will be to create Dow file this is which is important right click on this in new and then once again class so we will name it as course without inside this we will call here connection and then import test Mouse here in the import connection and now create one Constructor here would start coach down inside this Constructor we will call connection so we write here connection equal to DB connector right this file we will be calling DB connect DB connect dot get connection this function we will be calling here okay now let's create one function public word at course and here we will write course that means we will create pass here object of our course so right click on this and then import post so automatically it got imported this one this course.java now here give it right ready for inserting into database so prepared statement statement equal to prepare statement PST equal to connection Dot repaired repair statement foreign statement and then we will be writing query for insert into insert into courses the table name it will be the table name and here values now we will create the table so this courses will be our table name right click ok then let's import this so prepared statement has been imported and then it throws caption we can write this actually inside try and catch below so better wrap it with try and catch block yes this is better no so we have to specify the filter net so what will the three names of course they will multiple names course name uh duration category fees now let's go to MySQL workbench okay and log into here in here right click and create one new schema that means database so it will be overseas okay database name will be courses and then apply so successfully courses has been created now here right click on table and create table so this time the table name list name it as course not forces and then here we will provide course ID and then it will be Auto increment primary key not null then course name and then she's so it will be double for integer decimal okay is we can keep it as integer okay and then uh there is after this this is category right so category and then finally and one more finishing that is duration right duration so of course it will be integer also in okay so that's it now click on apply and then finally the table has been created so guys now what we need to do we need to change here our table name database damage courses which we have specified here [Music] okay let's change it to courses so here the field name will be course name then post name and second one is fees third one is category and duration category duration and in the prepared statement we will write here 1 2 3 and 4 prepared statement okay now here we will write the query for inserting the data so we'll be writing here PST Dot set string and then insert this this will be column number one and then here course Dot get personal guys this is the function name which is inside our course page here of course this get question we are calling here in our down file okay so similarly we have other fields so just copy paste two three four set string then second one is fees right so it is integer so set in here you get course ID no not course added uh duration second one is the fees [Music] you get the fish heavy created fish here [Music] no please we have not created so it will be private int fish as well and now we need to create here fish also so just copy paste this one in here we can put anywhere so get fees and then set peace then please here is here as well that's it that is why not twice it will not showing you so now it will be available gate fees right next one is set Stream post dot gate gate category right and then okay finally it will be duration that's it and this one will be once again settings because duration is integer that's why and now here PSP Dot Dot execute execute update for inserting the data we will be writing other functions also like delete display and update edit Etc but for the time being that's it first we want to show here inserting the data then one by one we will be doing other circular operation also so now it's cap back to here now this is the time to create this servlet file which will be handling the client's request for user display so now let's go to new and then click on servlet name will be course servlet okay finish right so we will be writing the code here inside our post method in the top let's initialize our database so we will be writing here course doubt then down and we will yeah we need to import this here of course now and then insert this Constructor you write here down equal to new course you will get object of this it's not required actually holds down foreign okay so better let's make it private private post out then here down into new code stop now create here object course equal to new codes okay we are just creating object of this course and then course dot set unfortunate insert this request Dot get parameter and then here insert this course name so what is this course name actually this course name is the field name so let's come back here and we have to input field we have to name it as name equal to Force name and here duration name equals to duration and we name we have to name it as select name equal to category and then finally fees name equals to face that's it now once again come back here so that is the course name okay similarly we need to hostname then just copy paste it so the second one is duration and face and category right of course we will have and here string course ID equal to request.getvironmental course adding so we will be using it for insert as well as update we will check here if if Force ID equal equal to null or course ID is empty then insert operation will be performed else update operation will be performed so please add this you will write the insert so we'll write here down DOT and force and then finally the course that's it or else here will be update query which we will write later so we write here course dot set course ID integer dot parsing then questioning we will set the course ID so guys here the logic is if course additional that means if it doesn't exist already or is empty then it will add the new course or it will update the course based on the ID so we will write here down DOT update user but we have not created this function that is why let's leave this for the time being blank because we are going to add new codes so guys it is the time to test our application if the data is being added or not one more thing here inside action yes insert action if you go to SRC and then Main say that INF file reduction then we can change here the URL so we will name it as courses okay we've got URL pattern is servlet URL now same URL we will provide here under our ad so that it will hit to the server link okay now let's close it right click on this and run it server finish right click on this and then this one finish starting okay now questioning Java duration for oh guys here the method name is spinning mistake okay so it will be method so let's start it again okay so let's try by adding Java and then four to five months this category ABCD whatever okay now let's go to SQL file and try to check if it got inserted or not so guys you can see it didn't insert now let's check the server what is the problem okay so it is saying that no value specified for the parameter two okay so what is the error I just got it here we have even one it will be 2 it will be 3 and it will be 4. okay so now get back here once again and try to insert okay now once again we will check if the data got inserted or not right click on this enter select tomorrow 431 whose name there is something wrong so we need to check it here okay the problem is you can see one two three four five right so what we can say one two three four so the first one is course name first one is course name and then second one is uh second one is this oh there is a big mistake so first one is course name first name first name actually so here will be saved duration [Music] same duration the first one is course name then second one is it is fees category and duration right so please here will be and then categories with family duration and we need to change here as well please set fees so we have just sit here set fees and set duration which described in here set fees where is this set phase and Gateway and also category and duration and as you can see the data type of this is integer right that is why what we need to do here we need to convert it into integer so we need to write here integer dot parse hint Parts int okay we need to convert this into integer so request dot get parameter so as you can see the the error is gone once again here also in T J Dot parts in okay and then request dot get parameter request dot get parameter one more will be this right so now we have of course name fees and this will be course category set category saved category set category functioning their right set category yes okay guys so now we will try and check if the data is getting inserted or not so how does it work we are taking the information here and setting into our shutter method here we are setting here and we are we are getting the value from here so now let's run this again okay so course name Java duration suppose duration is here two months and then category one two three we can provide here whatever category so the category is three and course fee I'm providing here thirty thousand okay now let's try to add okay so now we will check if the data got inserted or not guys you can see the course name has been inserted and fees 30 000 Category 3 and duration 2. that means two months so guys you can see our insert functionality is working perfectly but before we proceed ahead once again I would like to explain that how the whole thing works okay this is our JSP file right this is our GSP file so when we submit whether user submits the data where does it go it goes to the controller this file first okay and then in this controller the method is do post so it is checking so in insert this post method it is detecting here because we have mentioned here the post method you can see post method right method post and action courses which I've already mentioned that we have defined this URL into web.xml file so let me show you once again so that you can understand better if we go to searching name and then we back and shared with nothing and then wave.xml we have created Alias here so you can see rather than writing the course servlet we have just defined here so whatever name you will provide that be acting as a servlet so that's why we have provided here course now when we submit this data then goes here and then through a request dot parameter we get the value okay since these are string so there is no problem since this only uh integer that's why we have written here integer in case it was if it were okay so now the value is being the set here set page okay set course so where is it defined this one is defined in our model file this file right so there are two functions actually set and the gate set is setting into here in our servlet remember set file is setting into our servlet and get one is getting into our Dao file for inserting into the data got it so here HD set string and then get Force here you're getting and then get fish uh get category so we are setting the value here set and get right setting the value here and getting the value here and directly from here we are sending to my SQL Server so guys this is how the whole process works in the next task will be to whatever data we are inserting here we will display into our view file view.jsp so in the next chapter we will be discussing about that one only so stay corrected and keep watching chapter and now we will be creating function for displaying the data okay so we'll write here public list and then uh course in here get all courses and then this is function today so here and we need to import this list and this is our function it says that that there should be return function of course we will be writing that and here we will write here list Ed course then of course equal to new array list then released insert this so let's import this so we will import this from here and then try catch so here let's name it as courses and of course we will be returning here return courses okay which is not required here and one more curvlesses will be requiring here and we need to also import this one in here we will write here statement statement connection create connection okay and then result set import this one also and okay so we are getting one error which says cost to statement okay fine and then we will right here results it result set RS equals to statement dot execute query so it will ask you to educate query and result set we need to import cost results yet okay now we will run the while loop better let's do one thing uh change it to second option okay this one and now RS in statement dot execute query and select start from course and then now we need to write here while loop so this will be while rs.next and inside here let's create object of course equal to new course in here course Dot set course ID and then so what is the function name let's check here inside our set course ID right so here will be set course ID and inside this so it will be course set positive then get in and then course ID okay this is our field name so same way you will write here course dot set category and then inside RS Dot RS Dot get category eight get stream Ed okay so here is set course name rs.getstream right so get streams say get in the ID get stream rsps so wherever there is integer then get it and whenever there is uh string we right here gets D and finally add courses right courses dot add and what course okay and this courses we will be using in our JSP file so the next step is to so this into our view file okay we will be calling display this data into our view file okay so the first thing that we need to do is insert a head or anywhere it's not compensary we will just call this one okay to use jstl Tag into our this JSP file okay so we will be looping through this TR PR and TR before that we will look through the code so this tag tag is necessary to use the tag below jstl tag okay guys that is why we had in our com.xml file if you remember we had called this jstl5 this jst here that's why we had called it okay so now we are going to utilize this right now let's start writing the code here so we'll write here c f we will write here C then for each item and here courses so this is same courses what we have exported from here user Tower this courses okay so when did it go so courses and now we will close this C and now this is our closing time see for each so this is starting time and this is our ending time C for H so this will run into the loop now if you open this page directly then it won't show anything manage server so you can see it is showing blank so what we need to do let's go here and then insert our controller here in get method we will have to write here request dispatcher dispatcher view equals to new request dispatch not new request Dot dispatcher and here we will be writing and here will be view dot Js new DOT Js and then view Dot forward and then request and response request and response right but before that we need to send here request dot set attribute and then what what we are going to send here we are going to send here dot dot get users so guys we have already written this code here this one for serving all users this function get all users right we are calling this word to all users here in this servlet so dot get all users and it will be assigned to this variable and now this variable we are accessing here view Dot JSP file here courses web Force so now if I want to display here ID then one by one you will start displaying here so it will be C column out value dollar course and then course ID right course ID this is our field name so same way here we will display course name course named and here it is category I think category and here duration duration months and then here face okay guys so now this is time to check so let's go to servlet file and then run as server [Music] oh yes not yet JSP it will be redirected to view.jsp and then along with this variable so guys successfully we have displayed the data you can see here serial number name hostname category and duration and fees so guys so far we have successfully added the data and displaying the data from here so let's try by adding D1 say JavaScript and then duration three months and this one is dummy and fees add course now let's try to refresh this to check if it's coming in yeah so successfully the data is adding and display in the next chapter we will work on delete and edit section delete section so let's do one thing we will make it more modular now I am commuting this code and here we will write accents so string accents equals to request dot get parameter and then actions or simply X now so what we will do whenever there will be like delete update Etc then based on the action we will load or functions so now switch we will apply here switch case okay so X and then here case delete if there is delete then we will load here or delete function else in insert as part this one will be there in fact it will be not this will be default actually default okay so the default will be this one and in case the action is delete then delete function we will write here update update function will write here So based on the case okay now let's go to if you want to check if delete this action is working or not so let's do one thing system dot out dot print and then let's check here the action okay so let's run here so by default this will run default but when we in case we will write so let me show you what I mean so now let's check foreign if action equal to null then set action equals to default okay it actually null then the default action will be default now [Music] let's refresh it and see it is loading by default this but if I write here x n equal to delete then guys you can see so if you check here now in console then you can see Excel is showing delete that means what it is detecting the same way if I write here case edit then it should show edit refresh it and check here just I will change edit now let's see in the console it should show edit right that should be this is case delete and then this one is edit so you can see this edit is also displaying here that means what it is detecting the parameter okay now let's go back to our view dot JSP file and then we will write x n equal to which one is delete i trash this one right x n equals to delete and course ID cross ID equals to so it will be something like this action and then delete head course ID C out value then dollar course cosiding and here it will be closing so now if you refresh and check here and press Mouse here then you can see this one is showing here delete along with the ID so if you check here then it is showing delete right okay so that means what it is entering into this section deletions so here will be hint course ID equal to integer Dot pause int inside this request Dot get parameter and then here course ID and based on this now we will write here down DOT delete user delete course right but for this we need to create this function inside and insert this one course ID [Music] but we need to create this function going inside course down so let's create a function here public delete user and inside this we will pause here course ID in course edit and here prepare statement EST equals to we can copy from here this one or we have this one also this and here we will write delete query foreign statement PST connection Dot prepaid statement then delete from course where course ID this one now St dot set into and insert this one and then give TST [Music] one and then course ID and finally it will execute PSP dot execute query that's it and then after this yeah that's it in this one now let's get back here and then delete course you need to use every user delete of course you delete course right that's fine and then it will be forwarded to after deleting where it will be forwarded to this one to list page after deleting again so let's write here initial forward equals to blank okay so after deleting we will forward to forward equals to where View dot JSP and finally here we need to write dispatch this code at the end we need to write so that it will be forwarded so after deleting it will go new DOT JSP file okay so guys now let's open and check initially our list page should load yes so perfect now once we delete this yes it forwarded but what happened yes it is deleted but forwarding there is some problem so I just put it here forward now let's refresh this page and try to delete [Music] not available there is problem in forwarding anyway but the action of delete is working perfectly we'll do that here view dot JSP forward and then we need to also write this one okay so just I remove the code from here it is not required just we need to put here so what what is the logic I'm telling you first it is deleting it's not required also first it is deleting after deleting we need to forward to view dot JSP and then we need to also send this process did so that it will display there and so we have created a request dispatcher Del request.ticket inspector View and then we have created an instance in the same Rich instance we are forwarding to that page and with this attribute okay same attribute which we are passing in our default one okay here so now let's do one thing run this code we will add currently don't have the data first we need to add one or two so add JSP now JavaScript three months two alternative will also show message here and then C plus plus add Force now if you refresh then you can see there are two courses now if I delete then guys you can successfully deleting and solving one now if I once again delete then it will display clean so you can see how this is working first it is deleted and then it is forwarded to this page with this attribute okay then Del dot forward so that's it so guys successfully we have worked so far add View and delete in the next section of this video we will work on edit and update so let's see that section now in this section we are working we are going to work on edit section okay so in the edit section uh first let's go to Dow file here and we will create function for this public user course then get course by ID okay and insert this int course ID now create Force equal to new course try and catch inside catch everything will be same this inside right prepared statement this one we will require this one okay so prepared to statement PST connection investment and here we will write select start from course where the course ID equal to question mark and then PSP dot set into then here one and course ID now results we will create here we'll create here result set RS then PST query now while this RS dot next here we will fetch this one posted source of course get stream codes name for study category fees duration and then and finally this function will return user sorry of course so try is closing here catch is closing here and function is closing here so return will be inside this so this is while loop and then try sketch then return post and finally this one is for class this one mistake course array all together right course ID it will be select.com and then PST settings course ID entity now let's get back to our course in this servlet here so let's just comment it and write it before so we will write forward equals to add dot JSP and then we need to get this course ID from here and then okay so course ID the interior passing this for study will be fetched and then course force equal to dollar Dot get user by ID and this course and then request Dot set attribute then course and then discourse so what is happening here first we are sending our file to add.jsp we are not creating edit.jsp separately because same file will act as a add and edit right so here course ID we are fetching and then based on the course that you are passing here whatever data is coming we are forwarding it to the add page okay so if we run this application then we are forwarded to this list okay so better let's add a because we don't have any course list here so we will add now refresh and check it's coming here now and yeah one more thing in this list page where in this list page list will be viewed that means in this page we need to specify here just like this so XM and then this value we will also pass here in edit section but the action will be edit the only difference will be edit okay let's save it and then now Shake again refresh it and we place Mouse here still it is showing blank why did it is showing 8 but it's this way okay so let's do one thing let's start the application again I think it didn't get compiled properly that's why not this page actually we have to run from here then it will be forwarded along with the data because if you directly open okay so this one is showing eight here nothing why okay it was view actually so in edit also we need to specify this first one is let me show you okay here it is blank a TPU actually and this one will be edit edit share here starting from here closing you see out and this one is now this will be copied from here to let's copy the whole thing from here to here and just we will change it to edit edit okay fine this way for View and this will be for edit now let's say run and then if we check here now okay we have to specify here our servlet name also so here this slash is not required today only the action will be here okay so when we click on edit page course is missing here first will be course then action the location first will be quotes question mark question mark edit okay so now we are in the uh action edit section called the for me not loading right let's do one thing just copy this one here and we will forward this one right so it will be add JSP add JSP and then finally we need to pass this one here that is variable name will be credit and here edit as well so what will happen it will go to add page and then this course ID will be passing in this function the data will be fetching and this data will be passing there with this forward so now it should come to edit page okay and slash action equal to edit so we will click here now you can see guys we are in this page okay but the data should come filling so what we will do now let's go to and here in this add page we will write input type equals to hidden name equal to course ID and value equals to C out here C out and one more thing we need to call that jstl file here in this one also which we are calling View this one we need to include in this one only then this time will work so just copy this and then yeah input appearance here and then value equals to dollar user sorry course dollar course Dot course ID okay now let's check here okay so it is hidden right input type hidden let's view source and check which form yeah you can guys see this line input type header name equal to force ID and value is coming 8 right perfect now we will similarly pass these two name and other fields also here value will be course name course name and duration will be here and category and then course fee will be here okay so it's coming like this I think there is some mistake [Music] this value is not closing here [Music] this one is fine so if you refresh then you can see this one is coming this one is coming and this one is also coming and for drop down value we will use C if tag right so this is C if test we can provide any value then course dot duration equal to 1 then select it and see if close right same way if it's 2 then this one will be selected if it's 3 then this one will be selected okay so now let's try refresh it you can see guys it is three category right and two months duration so if you click on add this then you can see this one is coming to replace three right there is something wrong what is coming to equal duration three selected it is three oh it's not duration actually it is category right category now it should work yeah not serving three perfectly so guys successfully we have completed or adding displaying deleting and serving in edit and the last step which remaining is update so in the next chapter we will work on our update section hey guys so now this is time to work on update section okay so what we need to do let's go to uh course down in here public what update course and then of course course so we will write a function for updating the our course and again same thing try and catch the cash section will be this SQL exception and once again we will write this code update code here prepared statement PST and then connection so we will be writing here update code update course set course name equal to question mark and each one are the other course name and then category equal to question mark and then face equal to question mark and then duration equal to question mark where core study is adding now PST Dot so in this case we will use same one what we are doing in adding this now let's get back here and then let's paste this so course name will be updating get fees category duration where the ID and here of course one more field we that be ID in fifth one certain get course ID it course earlier what yeah sit for sorry send to get course ID okay it is course ID small one not big okay guys so this is our update query so prepared statement PhD connection prepared statement update course update course set course this it is and where ID is this let's try to update and yes not only that we need to forward English to view page but before that let's try if it's updating or not okay so let's close it and run the code okay this is not our failure we need to run this service actually yes so now click on edit edit is working perfectly now what we do Java I'll write here full stack Java integration I will put here six months and rather than three I will put here then I will make it 50. now so rather than add course we will just write submit here okay now click on editors Okay so let's see if it's updated or not no delete update let's see here yes we need to write update code here so we'll write here course dot set course ID ID we already have this and now we need to write update code so we need to write here down DOT update first after this we will redirect to thank you we will redirect to this one means list page after updating we will redirect to list page view page that means so let's try now let's click on edit the data is coming so we are writing here Mr Java make it six months rather than three make it 2 and 50 here right now let's click on addition to like there is some problem with updating so let's check what is the problem check the manual that's correspond to gtbc okay so there is problem in SQL very syntax where near First Step Java relatively duration duration equals to six okay so we have written update query so there is some problem in host Tau so let's check that in our update section delete then this is update so here is something wrong okay so if you see this then we can see there is sequence problem right the first one is will stack the category 5000. so first only course name then category course name in that category will be the second option so this will be two actually and then fees third that's fine integration will be fourth this is fine and then ID I guess now it should work properly let's shift Okay now click on edit and then open step six two and then 50. add course check again there is no problem didn't change right now it says no value specified for parameter 3. parameter three what is that no value specified or parameter three one two or three okay so there is some one small mistake because we have not specified a space okay server okay so now let's click on this update and this time I'm going to write here Java script and five and I'll make it uh one okay and this one 12. [Music] so guys you can see JavaScript category changing and fees 12 13th has been also shown here right so guys you can see that successfully insert update and we will put link here at the top so insert update and delete successfully we have completed in this course and this one is latest using uh Jakarta servlet and Tomcat 10 point X version so thank you for watching bye bye
Info
Channel: Tutorial Rays
Views: 12,921
Rating: undefined out of 5
Keywords:
Id: iKm6hM3SLuk
Channel Id: undefined
Length: 115min 1sec (6901 seconds)
Published: Thu Mar 30 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.