Java Programming 2 – Chapter 33 Exercise 9 – Fall 2016 [w/ subs]



00:00:00 – we're working on chapter 33 exercise
00:00:04 – nine which is the up on my screen here
00:00:06 – and let's read the problem description
00:00:08 – really quick
00:00:10 – it says right a jsf program that views
00:00:12 – inserts and update staff information
00:00:15 – stored in a database as shown in Figure
00:00:18 – 33.3 to will take a look at that in a
00:00:21 – second of the View button displays a
00:00:23 – record with a specified ID the staff
00:00:27 – table is created as follows
00:00:29 – all right now this should look familiar
00:00:32 – because this is the same table that we
00:00:35 – used in the previous chapter so we don't
00:00:37 – have to create it we don't have to
00:00:38 – populated with data what we might end up
00:00:41 – doing is logging in to the Chronos web
00:00:44 – server through PHP myadmin to make sure
00:00:47 – it's there so if you guys haven't done
00:00:49 – that process in awhile
00:00:53 – the address is Chronos etcd you /p HP my
00:01:00 – admin all lowercase and then i'll log
00:01:05 – into your account and then once you're
00:01:08 – logged in what you want to do is just
00:01:10 – want to double check the database that
00:01:13 – we've been working with is the java book
00:01:15 – database and you can just make sure that
00:01:18 – there's a staff table and then you can
00:01:21 – browse it
00:01:22 – see what data is in there so I have a
00:01:23 – couple pieces of data so we have
00:01:25 – everything we need
00:01:26 – ok so the database parts in place you
00:01:29 – guys have already struggled through do I
00:01:31 – have an account can connect to the
00:01:32 – account all that stuff so those
00:01:34 – mechanical components are done the
00:01:36 – database connection script are done so
00:01:39 – really our focus now is to create the X
00:01:42 – HTML document and the java code that
00:01:45 – does the interfacing with the system and
00:01:48 – get those two things to work together
00:01:50 – all right now what we're going to do we
00:01:54 – are working in netbeans and we are going
00:01:59 – to need to create all isn't that nice i
00:02:02 – have a break have all the answers right
00:02:04 – here folks
00:02:08 – no I'm not going to share yet when we
00:02:20 – get to NetBeans we're going to create a
00:02:21 – new project
00:02:26 – alright so now we're gonna write that
00:02:28 – you're hearing everybody laughed because
00:02:30 – I just asked them all to to coach me
00:02:32 – through so you can hear this all in the
00:02:36 – background this is all it moralized in
00:02:37 – the recording and it's going on YouTube
00:02:39 – so just so you don't
00:02:42 – big brother is watching alright we're
00:02:45 – going to create ourselves a new project
00:02:47 – so you can do a couple different ways
00:02:49 – you can click the toolbar the file menu
00:02:52 – create a new project are we going to
00:02:54 – java web application
00:02:57 – yep you bet and it's a web application
00:03:01 – so we're going to click Next she give it
00:03:06 – a name that makes sense maybe like
00:03:07 – exercise 30 39 right click next you're
00:03:23 – going to choose your server in this case
00:03:26 – we're so that we're going to stick with
00:03:28 – glassfish anybody tried tomcat yeah it's
00:03:32 – a pain to work with frankly when you
00:03:35 – when you work on real servers out out in
00:03:37 – the wild you know I know doing real work
00:03:40 – most of them will run tom cap and tom
00:03:43 – cat is one of those things that you let
00:03:45 – like a network admin kind of guy
00:03:47 – configure it for you and then it just
00:03:49 – works and you don't touch it because it
00:03:52 – can be a challenge to configure it's
00:03:54 – gotten better
00:03:54 – you know just mentioning all right I go
00:03:58 – ahead click Next if there's any other
00:04:00 – things that you want to throw in I don't
00:04:02 – know maybe javaserver faces what you
00:04:04 – think
00:04:04 – yes alright let's get that enabled you
00:04:11 – know if there's any libraries and stuff
00:04:12 – that you need to add you can throw them
00:04:14 – in down here but we're not in that
00:04:16 – situation then go ahead and click finish
00:04:18 – and then this builds out
00:04:22 – project folder for you now we're going
00:04:26 – to have two components here folks right
00:04:28 – we're going to have the part where we
00:04:30 – have to build the webpage we're going to
00:04:32 – use all those weird little h tags and F
00:04:34 – tags and all that stuff to do it and
00:04:38 – then the other thing that we need to do
00:04:40 – is we need to create a Java file and
00:04:42 – that java file is going to a bunch of
00:04:44 – different things for us
00:04:45 – the good news is this is good news that
00:04:50 – we already know how to do the database
00:04:52 – part right we've already done database
00:04:54 – connection to the scripts are already
00:04:56 – written
00:04:56 – we've already written code that will
00:04:59 – interface with the database and we've
00:05:02 – already written java code that allows us
00:05:06 – to create update destroy and retrieve
00:05:09 – records right so we have a lot of the
00:05:11 – pieces already in hand might have to
00:05:14 – modify what we at least have something
00:05:16 – that works that we can look at the other
00:05:19 – thing that might help you kind of
00:05:20 – envision the output a little bit is to
00:05:23 – go back to the book here and wherever
00:05:26 – that image is what was at 33 32
00:05:39 – alright so this is what we're building
00:05:40 – HTML is alright that's a piece of cake
00:05:45 – like if you're writing HTML this is like
00:05:48 – Hello HTML forms day one kind of stuff
00:05:52 – right so it's pretty simple but our
00:05:54 – trick is that we have to convert it into
00:05:56 – the javaserver faces syntax ok that
00:06:01 – that's the hard part for us so really
00:06:03 – the logical thing for us to do is to
00:06:05 – begin by building those components so
00:06:08 – I'm gonna start building the page and
00:06:10 – then we're going to build the code that
00:06:12 – makes it work
00:06:14 – alright let's jump back over to NetBeans
00:06:19 – all right now taking a look here at the
00:06:23 – document and you know we probably want
00:06:24 – to start changing some of the titles
00:06:26 – here may be exercised through 3.9 and
00:06:35 – obviously we're going to say something
00:06:36 – other than hello from facelets all right
00:06:42 – as we're building this I'm gonna quiz
00:06:45 – you a little bit of course you guys have
00:06:48 – a book sitting in front of you and
00:06:49 – hopefully you tried some practice
00:06:51 – exercises read the book and look at the
00:06:54 – lecture videos
00:06:55 – yes master yes maybe are now just a
00:07:04 – refresher on how this works
00:07:06 – remember that the weirdness here is like
00:07:08 – the whole fact that we're really working
00:07:10 – in xml file and that we we have a XHTML
00:07:14 – one doctype combined with an xml
00:07:17 – namespace that's the regular XHTML one
00:07:20 – but we're also using the custom javaone
00:07:22 – which allows us to use this H prefix and
00:07:25 – our tags and leverage the Java libraries
00:07:28 – that are part of the javaserver faces
00:07:30 – framework that basically take these tags
00:07:35 – and turn them into HTML elements so if
00:07:39 – we were to do this and straight HTML
00:07:41 – what we're seeing on the screen
00:07:44 – somebody just give me a like if I
00:07:46 – pointed an object on the screen
00:07:48 – tell me what HTML element you would use
00:07:50 – to create it what about staff
00:07:51 – information
00:07:52 – label paired paragraph could be h1 h2
00:07:58 – probably probably a paragraph alright i
00:08:03 – might even you know you might be some
00:08:06 – sort of a header kind of thing and it
00:08:08 – depends on what you want to style it so
00:08:10 – what about the ID text
00:08:12 – ok so really all these are labels right
00:08:15 – what about this
00:08:17 – yeah and in fact they're all text boxes
00:08:20 – right and what about these buttons
00:08:26 – what about layout components we have any
00:08:28 – way of components that we want to worry
00:08:29 – about okay you guys remember last time
00:08:37 – we went to work in the first exercise we
00:08:41 – used up can extract words from you we
00:08:45 – used some sort of a mechanism that are
00:08:47 – out aloud for certain amount of columns
00:08:49 – remember that it wasn't a table
00:08:51 – ok you guys think a great pain but
00:08:54 – that's in a GUI program in the panel
00:08:59 – great thank you very much i can tell
00:09:00 – Cindy Lou's the only one that read the
00:09:02 – book because if you read the book that
00:09:06 – would jump right into your head
00:09:08 – so basically what a panel grid does is
00:09:10 – it allows us to basically set up column
00:09:13 – so that you can interject these elements
00:09:16 – for example this role of HTML has 123456
00:09:22 – so we we would do a which we got a panel
00:09:26 – grid that has six columns
00:09:28 – ok
00:09:34 – alright so now that we've like talked a
00:09:36 – little bit about HTML structure what
00:09:38 – stuff we might use and kind of
00:09:40 – identified a few things we can go ahead
00:09:43 – and start putting in some of this stuff
00:09:48 – on the page so one thing for sure that
00:09:54 – we're going to do is we're going to get
00:09:54 – rid of this all right let's make a
00:09:59 – little room and we've already identified
00:10:01 – the fact that the top we got some text
00:10:04 – right now we have a couple different
00:10:06 – ways we can do a one one thing that we
00:10:08 – could do is we could just create a
00:10:09 – paragraph right and say staff
00:10:15 – information is that was supposed to say
00:10:16 – that's one way or if you wanted those
00:10:31 – are capping what i'm typing just be
00:10:33 – forewarned i'm going to be changing what
00:10:35 – i'm typing right now so dont copy to
00:10:38 – precisely another approach and what the
00:10:41 – author chose to do here and I think it's
00:10:43 – more for the the preference of teaching
00:10:46 – you some techniques is using some of
00:10:49 – these javaserver faces tags and what he
00:10:52 – used was the head tag to indicate that
00:10:55 – this is a header basically for what
00:11:01 – we're seeing below it now that's kinda
00:11:04 – weird right because the weird part about
00:11:07 – it is is not the same tag we're using up
00:11:09 – here
00:11:10 – yeah now this is what the author did
00:11:15 – what I do it that way if it's really
00:11:16 – static HTML frankly no no but you know
00:11:21 – what I might do is I might make it look
00:11:23 – at h 2 i'll let you guys proceed as you
00:11:26 – see fit
00:11:27 – there are some programmatic advantages
00:11:31 – to using nothing but the tags that are
00:11:34 – preceded with the H but there's no
00:11:37 – reason why I can't interspersed with
00:11:38 – just plain old HTML and I think you guys
00:11:41 – will be generally more comfortable with
00:11:43 – that the other thing that we're going to
00:11:46 – do is we need to create a four
00:11:47 – warm right so let's do that and you can
00:11:53 – see it created the opening and the
00:11:54 – closing for us right away see that means
00:11:59 – others do some pretty cool stuff see not
00:12:01 – only did it put in
00:12:02 – i didn't put in the closing all right so
00:12:04 – I'm talking ahead of myself here
00:12:06 – yeah I oh i thought it did
00:12:10 – yeah and I didn't and I didn't hit enter
00:12:17 – alright so looking again at this HTML
00:12:23 – output i created the staff information
00:12:27 – already now we're going to created a
00:12:29 – panel grid with two columns and that's
00:12:32 – how we're going to proceed we're going
00:12:33 – to for each row we're going to a panel
00:12:35 – grid each one's going to have a column
00:12:37 – each one's going to have a label each
00:12:39 – one's going to have input box
00:12:43 – alright so let's create the first one so
00:12:46 – this one is going to be h panel grid and
00:12:55 – we probably want to put in the number of
00:12:57 – columns here and 4 columns you just say
00:12:59 – columns and the number we decided was
00:13:03 – going to be what to write two columns
00:13:06 – and inside there we are going to do an
00:13:15 – output label notice how cool it is with
00:13:20 – what netbeans like the suggestions that
00:13:24 – it puts out there i think it's kinda
00:13:27 – neat and then hear the text that we're
00:13:30 – going to display instead of hard-coding
00:13:32 – it
00:13:32 – we actually just type it right here this
00:13:35 – is what's going to appear because we're
00:13:38 – working with xml we have to have that
00:13:41 – closing / inside there
00:13:44 – alright next thing that we're going to
00:13:46 – do is we are going to add the input text
00:13:53 – and once again we're going to have a
00:13:57 – value but here is where we're going to
00:14:00 – put
00:14:01 – in one of these things that looks like
00:14:02 – this and I don't have it yet so I can't
00:14:04 – tell you what it's gonna be but we could
00:14:07 – kind of pre decide like remember in the
00:14:11 – other exercise that we did where we
00:14:13 – basically have like a name scope right
00:14:15 – so whatever java file we create we put a
00:14:18 – little name at the top and we can use
00:14:21 – that name in combination with whatever
00:14:23 – method we're pulling from within the
00:14:25 – application we haven't created that yet
00:14:28 – so I'm just kind of coming to put that
00:14:30 – in right as soon as we create it will be
00:14:33 – able to come back and populate it but i
00:14:39 – do want to get that HTML structure in
00:14:41 – there first and I mean I can guess as to
00:14:46 – what I would make you know make it and
00:14:48 – call it but maybe being a little
00:14:51 – premature
00:14:53 – so that creates our first row we need to
00:14:58 – create the second row the second row has
00:15:01 – this is one with six columns
00:15:06 – yeah we you know what we could could
00:15:12 – copy and paste that just seems way too
00:15:14 – simple
00:15:17 – alright you know final copy and paste
00:15:25 – alright so what's the label we need last
00:15:29 – name first name middle
00:15:40 – you know and maybe instead of putting in
00:15:43 – stuff that's going to flag an error i'm
00:15:45 – going to clear the value out that we
00:15:47 – don't have to look at any underlines we
00:15:49 – just have to know to go back and then we
00:15:52 – can actually once again do a couple
00:15:56 – copy/paste that's our pattern right so
00:16:00 – this will be first and I think they just
00:16:04 – did mi so its second row if you're not
00:16:12 – in the habit ctrl s to save now working
00:16:22 – with these tags you know frankly is
00:16:23 – little strange I'll admit I'm sorry say
00:16:30 – that again
00:16:32 – oh I didn't do that thank you good catch
00:16:36 – yep thank you
00:16:41 – the otherwise we'd be wondering what the
00:16:43 – heck's going on
00:16:45 – alright so finishing off the panel grid
00:16:48 – here get the opening in the closing
00:16:50 – right away once again we're going to
00:16:52 – have the same pattern but this time we
00:16:54 – only need two columns again so let's
00:16:58 – type in columns to i still have that
00:17:04 – other stuff in my clipboard or buffer
00:17:10 – whatever you want to call it that one is
00:17:14 – for address
00:17:31 – all right let's see what we have to do
00:17:33 – next here city & state that's going to
00:17:35 – be four columns
00:17:48 – on this backwards here right
00:18:17 – double-checking here city-state
00:18:19 – apparently you don't need a zip code in
00:18:22 – the scenario and then we're going to do
00:18:28 – one more that also has two columns so
00:18:33 – I'm actually just going to copy this
00:18:34 – whole thing here since i got one with
00:18:35 – two columns already and paste it and
00:18:44 – that was telephone right yeah good look
00:18:54 – the point that was being raised was
00:18:57 – going to throw email in there too
00:18:59 – because we working previously we did
00:19:01 – that should we do that right away
00:19:03 – I mean it doesn't really take much it
00:19:06 – would just be basically another
00:19:08 – structure like this and we'll we'll have
00:19:12 – email sit below telephone so we're going
00:19:18 – to have an extra line so we'll just do
00:19:21 – email all right arm
00:19:27 – alright so that that pretty much takes
00:19:29 – care of all the you know the standard
00:19:32 – HTML kind of stuff in terms of like a
00:19:38 – regular layout the next thing that we
00:19:40 – have to do is get the buttons in there
00:19:42 – all right now if we jump over to the
00:19:46 – book again we're going to have to add
00:19:48 – four buttons those can also go in a grid
00:19:52 – like that and let's see if I have this
00:19:57 – here but that's gonna require four
00:20:00 – columns and we're not using a label or a
00:20:08 – text input text box so i'm actually
00:20:12 – delete all this stuff here and what we
00:20:16 – are going to use is an element that
00:20:21 – basically creates a button and to do
00:20:24 – that you do a command button
00:20:28 – alright we can add a value to it and the
00:20:32 – value is what the text is for the button
00:20:35 – if you look at the example its view
00:20:39 – insert update clear somebody remember
00:20:44 – that because i'm going to forget in
00:20:46 – about two seconds but it's already gone
00:20:49 – and you think i'm getting i can guess is
00:20:55 – so what they are though
00:20:56 – now the action tag is what it's going to
00:21:02 – trigger so when we hit this button this
00:21:06 – is going to allow us to trigger
00:21:08 – something on the java file that were
00:21:10 – about to create now once again we don't
00:21:12 – know what it's called
00:21:14 – we could make a gas here you know
00:21:16 – depending on what we call that java file
00:21:18 – so let's just say we call it dirt that's
00:21:21 – not what we're going to call it but i
00:21:23 – would probably create something inside
00:21:25 – the java file that would be that would
00:21:27 – be a method called view right so that's
00:21:30 – probably what I'm going to do so if we
00:21:32 – can think of a good name for this could
00:21:37 – we maybe you know kind of thinking ahead
00:21:40 – your little could we maybe call that
00:21:43 – file staff we do that because then that
00:21:48 – way the syntax kind of makes sense we
00:21:50 – call it staff view and and really if
00:21:54 – you're thinking like that or at least
00:21:56 – i'm thinking like that right now i could
00:22:00 – really kind of extrapolate and go back
00:22:01 – through and all these spots where it's
00:22:03 – empty for all these import text values
00:22:07 – we could probably say staff ID staff
00:22:11 – last name stabbed so you see the pattern
00:22:12 – and we're in what we do is we just
00:22:15 – knowing that advanced were kind of
00:22:17 – planning our class already but how we're
00:22:19 – planning our output so let me put in the
00:22:23 – four buttons first and then we'll go
00:22:27 – back and do the that exact thing so it's
00:22:31 – view insert update
00:22:38 – and clear insert update
00:22:53 – alright other thing is like we just
00:22:56 – mentioned i want to leave that on the
00:22:57 – screen for sec
00:22:59 – the other thing you should do is make
00:23:01 – sure i noticed here that this should be
00:23:04 – four columns not to i'm taking credit
00:23:09 – for something at one of the students
00:23:10 – actually gotten on recording it so we
00:23:15 – are in the mode tonight aren't we all
00:23:17 – right so knowing that we're going to
00:23:19 – start naming some of the stuff here like
00:23:22 – this
00:23:23 – I'm actually missing something here we
00:23:26 – need to get that hash symbol in there
00:23:28 – the pound sign and we need to wrap all
00:23:30 – this stuff with curly brackets you can
00:23:37 – see in the way that this auto types i
00:23:40 – should have had that as a forethought
00:23:41 – not an afterthought
00:23:43 – so when i do the ones above
00:24:00 – now this is where ID is helping you can
00:24:02 – sometimes be a little knowing but when
00:24:07 – you get into a workflow with one of you
00:24:09 – learn how to overcome these things
00:24:11 – alright so sihle the point here now I am
00:24:22 – scrolling up and I will scroll back down
00:24:24 – so don't don't go into panic mode as i
00:24:29 – would like to say alright so here
00:24:32 – knowing that we're going to go staff dot
00:24:36 – what should I call this one ID and can
00:24:42 – we just copy that pattern all the way
00:24:44 – through absolutely probably do it all
00:24:52 – lowercase like that so we are you doing
00:24:59 – something like this it actually once you
00:25:01 – get it into the flow of working the
00:25:04 – pattern is repetitive so they got one
00:25:10 – you kind of have mall trick is getting
00:25:17 – that first one know right
00:25:25 – ya know the funny thing is if i would
00:25:27 – have created my java file first the
00:25:31 – suggestions that would come up in the
00:25:33 – IDE would immediately pulled directly
00:25:35 – from that table I wouldn't have to type
00:25:37 – it but I'm kind of working in the
00:25:38 – opposite direction and that's you know
00:25:43 – that's actually pretty common when
00:25:44 – you're working with gooey stuff you tend
00:25:46 – to think of what the output is going to
00:25:47 – look like
00:25:48 – not that it's necessarily writer on any
00:25:53 – certain way but notice i'm also sticking
00:25:57 – with the convention of all lowercase
00:26:28 – he calls from phone that's called phone
00:26:49 – alright do a ctrl s to save don't lose
00:26:55 – your work
00:26:57 – the other thing that we might find a
00:26:59 – little helpful and Christian you were
00:27:02 – mentioning earlier that you know how
00:27:04 – about that thing we did a little status
00:27:06 – you know what I did that last time and i
00:27:09 – actually put it in there so I'm copying
00:27:12 – from my own work here
00:27:13 – you guys are wondering i'm going to put
00:27:16 – another panel great at the bow bottom
00:27:19 – it's only going to have one column so I
00:27:21 – don't need to say columns it's just
00:27:23 – gonna be there and what I'm going to
00:27:25 – throw there is just a little place to
00:27:30 – output some text so it doesn't really
00:27:32 – have to go into a structure you know
00:27:34 – like with these other input text fields
00:27:38 – just going to be test to the screen and
00:27:40 – the the thing that they have for that is
00:27:42 – called output text that works pretty
00:27:46 – well for it
00:27:47 – arm your level over we have to do a
00:27:54 – value and the value is going to be staff
00:28:02 – and we'll have something called status
00:28:05 – the other cool thing though is that you
00:28:10 – guys know that you can actually throw
00:28:12 – CSS in here yeah your color and what
00:28:20 – color should we throw in bed
00:28:27 – yeah it's kind of thinking or maybe blue
00:28:31 – alright i notice this one we had closed
00:28:39 – it though and put / inside i actually
00:28:44 – put it outside because what it's going
00:28:46 – to do is it's going to insert text here
00:28:50 – that's gay works a little bit
00:28:51 – differently alright so just as a little
00:28:56 – bit of a chance for you guys to learn
00:29:01 – from this code i'm going to scroll to
00:29:04 – the top
00:29:07 – this is also for the people copying at
00:29:08 – home
00:29:10 – pause the video on pause next block
00:29:23 – and then the very bottom
00:29:28 – alright if you want to see what this
00:29:31 – looks like
00:29:32 – I i did launch it just a couple seconds
00:29:34 – ago to test it and it did work at the
00:29:36 – concern that maybe since we haven't
00:29:39 – created the external java file with with
00:29:41 – this stuff
00:29:42 – it didn't know what to do but apparently
00:29:44 – just ignores it so I came up here I
00:29:47 – selected my browser and then I hit the
00:29:52 – Run button and you can see it generated
00:29:55 – the page now my page launched really
00:29:59 – quick and it's because I had already
00:30:00 – initiated the server so the server is a
00:30:03 – piece of software that you know it's
00:30:04 – pretty significant piece of software so
00:30:06 – its software that has the launch run
00:30:08 – initialize then read the page load the
00:30:11 – page and push it to the browser so after
00:30:15 – the first time you've launched it the
00:30:17 – subsequent launches will be almost
00:30:18 – immediate because the server software
00:30:20 – keeps running now when it is running you
00:30:25 – guys should be aware that down here at
00:30:27 – the bottom you're going to get some
00:30:32 – output right so this is output from the
00:30:36 – application so it's showing you what's
00:30:40 – happening it you know i think it's
00:30:42 – fascinating because if you actually read
00:30:43 – here
00:30:43 – it even shows you all this information
00:30:46 – about my machine like all the folders I
00:30:48 – store in etc it also indicates that
00:30:53 – there's some database stuff going on in
00:30:55 – the background that stuff that we put in
00:30:57 – yet but there's an interaction with the
00:30:59 – database from the web server with the
00:31:02 – database to get it to run and then
00:31:04 – glassfish is the server software that's
00:31:08 – running in the background
00:31:09 – what's fascinating about that is
00:31:11 – anything that we do in the browser when
00:31:14 – the servers running will be logged here
00:31:16 – just like on a real web server if for
00:31:22 – some reason you want to stop the server
00:31:24 – you can just hit one of these little
00:31:25 – buttons over here or refresh it restart
00:31:30 – and there are times when you can write
00:31:31 – code that can make it mess up but
00:31:33 – generally speaking once the servers
00:31:35 – running you're fine
00:31:36 – the other thing you should be aware of
00:31:38 – is always look at the the output here
00:31:41 – you notice well first of all localhost
00:31:45 – refers to your own machine right the
00:31:46 – loopback but then there's a port number
00:31:49 – of a DAT that's default for glassfish
00:31:52 – remember the regular HTTP web port is 80
00:31:57 – if you're using a tu don't need to
00:31:59 – specify it but then interestingly take a
00:32:04 – look at the output that follows it right
00:32:07 – we're not loading up our index that
00:32:11 – XHTML notice that it's loading up the
00:32:16 – project name it provides clean urls
00:32:18 – another advantage mean it's very much a
00:32:23 – content management system that's set to
00:32:25 – do the same thing
00:32:26 – alright if we look at the resulting HTML
00:32:30 – code if you do a right-click take a look
00:32:33 – at what happens
00:32:34 – boy it took all that stuff and put it
00:32:38 – into a table
00:32:39 – yeah put everything into separate tables
00:32:46 – okay can we just say that is probably
00:32:49 – not the I wouldn't write HTML that way
00:32:51 – but whatever it works
00:32:56 – quick could I have just come in and
00:33:01 – instead of doing what I did
00:33:03 – could i just take the output labels
00:33:04 – input.text and just create any sort of
00:33:06 – HTML structure i want absolutely but
00:33:11 – yeah I mean the reason I did this is to
00:33:13 – show you that there's you know the java
00:33:16 – way to do it
00:33:17 – we don't have to use Java take stroke
00:33:21 – you would want to use the form tag and
00:33:25 – any of the fields that are doing java
00:33:27 – interactions need to have those tags
00:33:34 – ok with that in mind it's now time to
00:33:38 – move forward and create the Java file
00:33:41 – that goes with this
00:33:43 – alright so since we're going to build a
00:33:46 – java file we gotta find a place to put
00:33:48 – it on the job of files you can see I
00:33:51 – have a previously can completed version
00:33:52 – of this the job of files and
00:33:55 – up in the source package folder right
00:34:00 – here so that's what we're going to put
00:34:04 – it so we go to create it
00:34:06 – i'm going to right click on source
00:34:07 – packages and i'm going to say knew what
00:34:11 – java class maybe that would make a lot
00:34:18 – of sense
00:34:20 – alright so what do we want to call the
00:34:22 – class name could be called staff we just
00:34:28 – have to have a capital S which package
00:34:34 – are we going in too deep
00:34:37 – the default is fine which we don't
00:34:39 – really have to specify new class right
00:34:46 – right and then i'm going to go ahead and
00:34:49 – click finish and you can see that place
00:34:54 – the file right here
00:34:55 – alright so now we've got a little bit of
00:34:58 – work to do i'm i'm blowing away all the
00:35:00 – comments and now we're just writing a
00:35:08 – Java program and remember we have the
00:35:12 – advantage here where we can borrow from
00:35:14 – our own work which is handy
00:35:23 – alright so we're having a little
00:35:24 – discussion here while the video is pause
00:35:26 – that should have created a managed being
00:35:28 – instead of creating just the java file
00:35:31 – even though the truth is it would still
00:35:32 – work so I'm actually going to come in
00:35:34 – here i'm going to delete this file and
00:35:37 – all you have to do is right click delete
00:35:42 – alright so now we need to right-click
00:35:50 – the project note again and this time
00:35:52 – we're going to create a white a managed
00:35:55 – to be alright and we're going to call it
00:35:58 – staff going to go into the default
00:36:03 – package and is there anything else that
00:36:07 – we need to set all we already know that
00:36:10 – it's going to preset the name of itself
00:36:14 – basically to staff i'm just going to go
00:36:17 – ahead and click finish
00:36:19 – alright so you can see I'm being a
00:36:24 – little hasty here so i'm going to be
00:36:25 – deleted what i just did again because i
00:36:28 – have students that a apparently know
00:36:31 – this stuff better than I do at least the
00:36:34 – people that read the assignments and and
00:36:36 – the chapter so that we skipped another
00:36:39 – step again so we're still going to name
00:36:41 – its staff but the part that we missed
00:36:45 – was we need to have an application scope
00:36:48 – right is it we know we I've had this
00:36:57 – discussion many times over
00:37:00 – you can do it a couple different ways
00:37:02 – are when we did 33 or 33 we even do that
00:37:09 – here did we we did the previous one did
00:37:12 – we even set it yeah we did
00:37:20 – arm so all right so what do we do that
00:37:23 – you guys read the book
00:37:30 – ok kind of further discussion a little
00:37:32 – bit about the scope you know there's we
00:37:36 – can actually use different ones here and
00:37:38 – they would all work just fine because
00:37:40 – the kind of stuff that we're doing is
00:37:42 – fairly simplistic but in terms of formal
00:37:45 – definition we have these types available
00:37:49 – to us know what let's just read through
00:37:52 – what it says it says request scope is
00:37:54 – alive in a single HTTP request one
00:37:58 – button press a single request
00:38:02 – ok but think about that for a second if
00:38:06 – you load a web page and you click that's
00:38:12 – a single request it will do exactly what
00:38:14 – we asked to do so that's fine
00:38:15 – alright let's read the next one of you
00:38:20 – scoping lives as long as you are on in
00:38:22 – the same JFS page so that would work too
00:38:28 – yeah that's where I'm leading into
00:38:31 – session scope the beat is alive for an
00:38:33 – entire web session between client and
00:38:35 – server this is the one we would probably
00:38:37 – skipped because a session also kind of
00:38:41 – indicates that we would have other
00:38:43 – components running that are keeping a
00:38:45 – connection open between client and
00:38:47 – server frankly this one would work too
00:38:50 – but this is probably what I would stay
00:38:52 – away from the last one application scope
00:38:56 – lives as long as the web application
00:39:00 – runs that is probably the most open out
00:39:05 – of all of them
00:39:06 – so in terms of which one we're going to
00:39:08 – choose you know it depends
00:39:17 – well in yeah that's a good question
00:39:22 – yeah that that's my thinking that's what
00:39:27 – the author a solution application scope
00:39:31 – to me seems the most flexible but I
00:39:33 – certain you certainly could do it with
00:39:35 – requests and view just as efficiently
00:39:38 – what what you would probably end up
00:39:41 – figuring out is to try to do like
00:39:43 – multiple actions and it's not working
00:39:45 – why is it not working then you change
00:39:46 – your scope it works ok know what we're
00:39:53 – going to do though
00:39:54 – let's say if you decide to do your final
00:39:56 – project using jsf this would be relevant
00:40:01 – for you where you might want to keep
00:40:04 – application scope
00:40:07 – alright so let's go ahead i'm going to
00:40:13 – go with application sculpt so now that
00:40:17 – we're we're really learning a lot about
00:40:19 – this by creating and destroying it
00:40:21 – multiple times and you notice there's
00:40:26 – other scopes that are mentioned that
00:40:27 – aren't in the book right all right so
00:40:33 – we're going to application scope and
00:40:34 – we're going to click finish and we're
00:40:36 – sticking with it
00:40:38 – all right we'll see so I'm going to
00:40:41 – remove all the comment marks here just
00:40:43 – to save a little screen space they
00:40:47 – already have pre-populated a couple
00:40:48 – libraries for us and you can see if they
00:40:50 – have the public class created and they
00:40:54 – have a constructor recreated now we are
00:40:57 – going to need in this class file to
00:41:00 – create a bunch of data fields and i'm
00:41:06 – going to go ahead and create a number of
00:41:08 – them in fact I'm going to follow the
00:41:10 – form of the form right remember all the
00:41:13 – fields
00:41:19 – yeah in fact we we decided that all
00:41:23 – these are lowercase right
00:41:33 – so this party I hope hopefully don't
00:41:35 – have to coach you through this part
00:41:37 – people watching the video like what are
00:41:43 – these guys doing
00:41:57 – yes the air command buttons
00:42:04 – and then we had a telephone and then we
00:42:09 – have to add email as well because we
00:42:11 – were doing that with earlier exercises
00:42:13 – you're right you're right Christian I
00:42:18 – mean I named it phone not telephone and
00:42:21 – what he's referring to you can overhear
00:42:24 – on is for this one i opted to use phone
00:42:28 – so that's why i'm not using telephone so
00:42:35 – if you are working on the earlier
00:42:36 – exercise from the previous chapter we
00:42:39 – did database stuff and you did not add
00:42:41 – email to your database you wouldn't have
00:42:46 – to add that because it would match up
00:42:48 – with your table but we did so we are
00:42:50 – we're also going to do a string for
00:42:54 – status
00:42:56 – all right now I'm gonna put a little
00:43:02 – comment here
00:43:10 – it so we're going to add this thing
00:43:14 – called prepared statements here it is
00:43:16 – it's a type of class I haven't put it in
00:43:19 – ya
00:43:20 – ok because i want to kind of build some
00:43:23 – of the other stuff out first one thing
00:43:32 – that we probably want to do is we
00:43:36 – probably want to get that database
00:43:37 – connection going I'm thinking and I'm
00:43:41 – going to start building that in fact I'm
00:43:43 – going to do it in the form of a try
00:43:45 – catch and i'm going to create a method
00:43:50 – to do it
00:43:51 – ok we are going to have a constructor
00:43:53 – and I'll talk about that in a second but
00:43:56 – I want to get the database part out of
00:43:58 – the way so what I'm going to do is I'm
00:44:00 – going to create a private here and i'm
00:44:03 – going to call it it's not returning
00:44:06 – anything
00:44:07 – let's call it in it d be so initialize
00:44:13 – database we do like that we will not
00:44:18 – pass anything to it and then I'm going
00:44:21 – to a try
00:44:22 – except probably curly bracket there i
00:44:26 – think and then we are also want to have
00:44:31 – a catch and I'm not sure either and
00:44:36 – cooperate way because I'm not doing it a
00:44:40 – nice smooth stream here you know because
00:44:44 – it will auto type stuff for you provided
00:44:48 – you follow their patterns well let's
00:44:50 – just do the tripod first we can always
00:44:51 – add the other stuff now I have a
00:44:57 – database stuff that I've used before so
00:45:01 – what I'm going to do is I'm going to
00:45:02 – just copy and paste it in
00:45:13 – alright so let's get that database stuff
00:45:17 – in there I'm not gonna reinvent the
00:45:19 – wheel here i'm just going to some of my
00:45:22 – other code that's already prepared and
00:45:26 – I'm just pasting it in and I do have to
00:45:29 – tweak some things here but first of all
00:45:31 – I'm not connecting to localhost right
00:45:35 – i'm connecting to Chronos
00:45:48 – and I'm Chronos you also have to preface
00:45:51 – the database name with your username and
00:45:54 – underscore remember and then you have to
00:45:59 – actually put in your real username and
00:46:02 – password in plain text in my password is
00:46:08 – actually password which is the most
00:46:13 – secure of all passwords right all right
00:46:17 – so we have a few different things here
00:46:19 – we need to load up so let's pull up some
00:46:28 – libraries
00:46:36 – alright so we got a connection we need
00:46:42 – to get our driver manager so I'm just
00:46:44 – clicking at the to the end of that
00:46:47 – keyword and control space and then just
00:46:52 – take a look at the the drivers that are
00:46:54 – for the libraries that are being loaded
00:46:55 – up now it's noticing that we don't have
00:47:03 – this driver so we have to add it
00:47:06 – ok and it also is throwing the same
00:47:11 – exception here and the only way that we
00:47:18 – can catch a sequel exception if there's
00:47:22 – a problem with the database is to once
00:47:24 – again drop in a library
00:47:27 – oops
00:47:39 – so that added this library all right and
00:47:45 – it also encapsulated us inside of a
00:47:49 – throws sequel exception just in case the
00:47:53 – databases and connects so if you need to
00:47:59 – look at all of that I'm hoping this part
00:48:03 – for you is ok right now I know you're
00:48:07 – typing really fast but these are the
00:48:08 – library's up top another thing you can
00:48:13 – do if you want to be really efficient
00:48:14 – about if you're not sure which sequel
00:48:15 – libraries you can put in you can just
00:48:17 – get rid of all of these and just have
00:48:20 – one and put a star or asterix here right
00:48:23 – and just loads all of them
00:48:24 – that's not really considered efficient
00:48:26 – oh it's better to load the stuff that
00:48:28 – you only the stuff you need is yeah well
00:48:33 – because it has to pull all that stuff
00:48:34 – and so here i'm hovering over this one
00:48:37 – and it says unreported exception
00:48:42 – classnotfoundexception must be Carter
00:48:44 – declare to be thrown all enter show
00:48:47 – hints
00:48:48 – ok it's all I educate sorry I know the
00:48:52 – reasons doing that but trying to get the
00:48:54 – little box to come up but it's setting
00:48:56 – out to come up there
00:49:10 – no this is it says add a catch clause ok
00:49:14 – but the catch that it's going to throw
00:49:19 – it is this isn't the one that we're
00:49:20 – looking for the catch that we really
00:49:23 – want and I was being a little hasty
00:49:25 – there is we just want the plain old
00:49:27 – exception like if it doesn't work
00:49:29 – that's the one that we want and in
00:49:32 – addition really all we need to do here
00:49:35 – is do something like this now calling an
00:49:41 – exception ex is kind of like a
00:49:43 – convention if you're wondering i'm not
00:49:45 – just putting that out of thin air but
00:49:49 – i'm going to do this printstacktrace and
00:49:51 – that'll be fine it's okay if you copy me
00:49:54 – doing this
00:49:55 – that's fine
00:50:14 – are we took a pause here so we could
00:50:16 – kind of catch up we are going to be
00:50:18 – adding and I had somebody ask we're
00:50:20 – going to be adding more stuff here
00:50:21 – absolutely but one thing that we should
00:50:25 – consider is all the real simple basic
00:50:27 – things that you do with these types of
00:50:31 – applications so for example arm in a
00:50:36 – constructor function one thing that you
00:50:39 – can do arm to instantiate is basically
00:50:45 – take all of the fields that we have
00:50:49 – declared here and give them a value when
00:50:56 – you construct right here's a here's an
00:50:59 – interesting the way it's a piece of
00:51:00 – syntax you probably haven't seen before
00:51:02 – like one common approach would be lets
00:51:06 – say we go like email equals empty quotes
00:51:09 – right and what we could actually did
00:51:11 – that above right but when we construct
00:51:15 – that's kind of what we want to do we
00:51:17 – want to create an empty 11 way to kind
00:51:21 – of do all of them at once and check out
00:51:23 – this technique
00:51:28 – this is probably one you haven't seen
00:51:32 – but i think it's worthy of showing it to
00:51:34 – you and I see I'm copying my code from
00:51:39 – somewhere else where somebody use
00:51:41 – camelcase like they probably we probably
00:51:43 – should have but i'm just taking all the
00:51:46 – fields and basically sending them to
00:51:49 – empty quotes 1 is equal to the other
00:51:51 – equal to the other ultimately they're
00:51:52 – all equal to empty quotes as necklace
00:51:56 – intex it's almost too simple
00:51:59 – alright the other thing that we want to
00:52:02 – do when we construct is we want to
00:52:04 – initialize the database so we're going
00:52:07 – to do that right here now this is
00:52:13 – throwing an error also
00:52:18 – a lot i'm worried about the sequel
00:52:21 – exception i think that enough that will
00:52:23 – stop us or not I'm doing all to enter
00:52:30 – right now it's saying no suggestions
00:52:32 – that thank you
00:52:36 – oh it's okay i could be that we're yeah
00:52:42 – we're little doesn't realize we're doing
00:52:44 – that down below
00:52:47 – ok so I see what they're doing they want
00:52:51 – to just throw a sequel exception if it
00:52:53 – fails here that's fine just do it says
00:52:58 – it's not going to break anything one way
00:53:00 – or the other
00:53:00 – alright the other thing that will want
00:53:03 – to do is for all the data fields that we
00:53:06 – have declared setters and getters would
00:53:10 – be good let's think
00:53:12 – has anybody learned the shortcut way of
00:53:15 – doing it and ok somebody saying
00:53:18 – right-click yeah this
00:53:23 – yeah this is an eclipse yeah but let's
00:53:27 – put on a challenge
00:53:29 – alright so I they put up the challenge
00:53:31 – and I did get somebody figured out it
00:53:33 – was within a minute or two so if you
00:53:36 – highlight all these fields here all
00:53:38 – these variables and just do a right
00:53:41 – click insert code setter and getter and
00:53:49 – sure all of them
00:53:54 – alright so we have all our setters and
00:53:59 – getters now for the data fields
00:54:01 – that's a lot right we just save like
00:54:05 – understood a hundred lines of code and I
00:54:07 – didn't even try
00:54:09 – what I do is I highlighted all of these
00:54:13 – yeah it doesn't have to be highlighted I
00:54:19 – guess that that's kind of a habit I have
00:54:21 – insert code notice it also does a
00:54:31 – constructor automatically to now these
00:54:34 – are little tricks that you're gonna pick
00:54:35 – up over time but you know I also want to
00:54:38 – get the concept so notice how everything
00:54:41 – is named all of them have this all of
00:54:48 – them have getting set all of it son
00:54:51 – camelcase and pretty straight ahead
00:54:55 – stuff all right
00:54:59 – the other thing that we're going to want
00:55:00 – to do is we're going to want to set up
00:55:05 – some prepared statements and really you
00:55:07 – know I left a little note here for
00:55:09 – myself and this is where we're going to
00:55:11 – add them and so you guys may as well
00:55:12 – let's get moving on it so we're going to
00:55:16 – prepared statement and what I'm going to
00:55:23 – do is a trend oka easy way to abbreviate
00:55:27 – this I don't like using such a long
00:55:30 – keyword so why don't we do a PS view
00:55:37 – prepared statement for view
00:55:39 – ok so that's my mindset here and then
00:55:43 – very much the same way and I guess we
00:55:45 – should add that that library
00:55:52 – and then we're going to do yet we're
00:55:54 – going together buttons as well yeah
00:56:03 – hover and then alt enter or go to the
00:56:08 – end of it and press ctrl space
00:56:12 – yeah now I want you to think about this
00:56:15 – too we are going to need your statement
00:56:17 – for view we also definitely have to do
00:56:21 – one for insert we also have to do one
00:56:26 – for update
00:56:29 – can you tell me why I wouldn't need to
00:56:32 – do 14 clear we're just going to get rid
00:56:37 – of stuff we're not really doing
00:56:38 – statement we're just clearing form
00:56:40 – alright so that's actually kind of cool
00:56:42 – because then how would i do a clear
00:56:50 – watch and learn young ones watching mark
00:56:53 – i know this is all being recorded two
00:56:57 – which is the scary part
00:56:59 – so one of the methods that we have to
00:57:01 – write is clear and I've already got a
00:57:06 – written so I'm just pulling it in and
00:57:08 – I'm going to correct my little typos
00:57:09 – here you know that statement that we
00:57:11 – used up top to do the the construction
00:57:13 – we're using that same thing we're just
00:57:16 – clearing everything and we're going to
00:57:24 – throw email into the mix as well as we
00:57:26 – have that in ours and then I'm also
00:57:28 – taking the string status and I'm
00:57:32 – throwing a message with it so after them
00:57:34 – to do with all those buttons every time
00:57:37 – a button is pressed is going to generate
00:57:39 – a status message like it worked didn't
00:57:41 – work
00:57:41 – whatever just something to show that the
00:57:44 – user what happened
00:57:57 – all right now it's now it's time to do a
00:57:59 – little bit more work
00:58:00 – let's go back to the database section
00:58:03 – here and you can see I left a little bit
00:58:06 – of space and what we're going to do is
00:58:09 – we're going to start preparing ourselves
00:58:11 – for the queries they're going to go back
00:58:14 – and forth
00:58:15 – alright so this is going to be part of
00:58:18 – the initialization process because we
00:58:20 – need to kind of preset a format that's
00:58:23 – going to make our life a little easier
00:58:25 – so watch what I do here i'm going to
00:58:28 – create a string and remember the whole
00:58:33 – point of this is to help do our work and
00:58:38 – the other methods
00:58:39 – that's why I'm doing it and i'm going to
00:58:45 – call it query view so this is going to
00:58:53 – be the query that's going to be used to
00:58:57 – do a view that's why I guess I just said
00:59:00 – that did not and we're going to do a
00:59:05 – select statement we're just writing
00:59:06 – regular sequel quote now we're going to
00:59:08 – select in the format of how our database
00:59:13 – is created so i'm actually gonna go to
00:59:15 – PHP myadmin here so see how we have our
00:59:18 – fields name their camel case its upper
00:59:21 – case and upper case in both those
00:59:24 – otherwise everything else is lowercase
00:59:26 – telephone is actually telephone that
00:59:29 – phone in the database so i need i need
00:59:31 – to know that so we're going to select ID
00:59:36 – right
00:59:38 – no no we're not that's not that's not
00:59:42 – true
00:59:42 – we're going to select and I'll explain
00:59:45 – why last name first name middle initial
00:59:58 – what else we have address city state and
01:00:06 – around space here
01:00:10 – all right I'm gonna go to the next line
01:00:13 – and go on to the next line i need to
01:00:15 – concatenate steady-state telephone
01:00:29 – email anything else
01:00:36 – alright those are the fields now we can
01:00:38 – put in our front and if you want to your
01:00:40 – your sequel statements uppercase you
01:00:42 – more comfortable with that
01:00:44 – go for it over the years I've actually
01:00:46 – grown away from that
01:00:48 – so from what table are we pulling it
01:00:51 – from uppercase s in my case right
01:00:56 – it is alright email from staff alright
01:01:04 – and then where ID equals question right
01:01:17 – trust me it's right and we do semicolon
01:01:23 – at the end right that's to set up the
01:01:26 – query for the view now the other thing
01:01:31 – is so now we're going to a prepared
01:01:36 – statement we already have one created
01:01:39 – right we have the PS you and that's
01:01:45 – going to equal the connection and then
01:01:51 – we're just going to issue you can see
01:01:54 – right up top here prepared statement or
01:02:00 – prepare statement technically and then
01:02:02 – thing that we're going to stick into it
01:02:04 – is query view now guess what we're doing
01:02:12 – this again so we do a string to query
01:02:17 – for insert once again
01:02:22 – typing a sequel statement this time
01:02:25 – we're going to do an insert we're going
01:02:28 – to into into the staff table and then
01:02:33 – we're going to throw stuff in the order
01:02:35 – that it's in the database so we're going
01:02:36 – to say ID ID comma
01:02:42 – last capital and name and now I just I
01:02:51 – just want to be clear on this to folks
01:02:53 – we're going and column order now right
01:02:58 – so our form might say first name last
01:03:00 – name but this is saying last name first
01:03:02 – name so we have to be in the order if
01:03:04 – we're going to use this syntax and
01:03:06 – sequel we have to be in the same order
01:03:08 – then we'll do middle initial
01:03:12 – let's drop the next line and concatenate
01:03:14 – and we should probably put a comma after
01:03:20 – middle initial right and then after
01:03:24 – middle initial we have address city
01:03:32 – state tell the phone email
01:03:43 – close your parentheses the values that
01:03:47 – were sending and this is a good spot to
01:03:53 – concatenate again and the values that
01:03:57 – were going to send our well we don't
01:04:00 – know what we need ? somebody we have
01:04:04 – 123456789 two three four five six seven
01:04:20 – eight nine right on two three four five
01:04:28 – six seven eight nine and we got our
01:04:33 – close double quotes and then a semicolon
01:04:36 – once again we have to do a prepared
01:04:39 – statement insert that's going to equal
01:04:43 – connection
01:04:48 – prepare a statement query insert
01:04:57 – semicolon also have to do one for update
01:05:16 – and updates got its own sequel command
01:05:19 – will do an update staff and we're going
01:05:25 – to set and then here's where we're going
01:05:28 – to like take each one of the fields and
01:05:30 – basically do this pattern so the pattern
01:05:32 – is going to be last name equals ?
01:05:39 – first-name equals ? get middle initial
01:05:54 – up here too and let's drop to the next
01:05:59 – line and concatenate
01:06:22 – what comes next telephone
01:06:30 – and you know
01:06:35 – alright then we'll get a little uh we're
01:06:39 – gonna have one more line here and we're
01:06:42 – going to throw in our i'm going to throw
01:06:45 – an extra space here we'll throw in our
01:06:50 – where ID equals whatever it equals
01:06:56 – following the same pattern we're going
01:07:05 – to a prepared statement update that i
01:07:10 – use camelcase i shared it
01:07:37 – alright and that's going to do that part
01:07:38 – of it so this is really this is all of
01:07:40 – our database stuff kind of happening
01:07:43 – right here but what's cool about this
01:07:46 – approach using the prepared statement is
01:07:49 – we have like the framework for doing the
01:07:51 – queries in place that way when we're
01:07:54 – pulling stuff in from the form it
01:07:56 – dynamically will get inserted into these
01:07:58 – positions and execute all right we still
01:08:03 – need to setup methods though that are
01:08:06 – going to populate all those question
01:08:08 – marks basically so now that we've
01:08:11 – completed this part of it
01:08:13 – the next part of it is to build a method
01:08:17 – for view insert and update we already
01:08:22 – did clear clear doesn't take anything
01:08:25 – alright I'm going to pause for a second
01:08:32 – alright so now that we've created all
01:08:36 – these you know pre-configured queries
01:08:39 – and stints equal statements
01:08:41 – remember we're doing this to kind of
01:08:43 – save ourselves a little bit of hassle
01:08:44 – having that like manually code each time
01:08:47 – we are now going to build methods for
01:08:51 – view insert and update and that they're
01:08:53 – going to have exactly those names so
01:08:57 – believe it or not the ones that are
01:09:00 – going to be the easiest to create our
01:09:01 – insert and update because basically
01:09:04 – they're really similar so and to me it
01:09:10 – makes sense to create those first so i'm
01:09:12 – going to create a little room here and
01:09:15 – i'm going to create let's start with
01:09:17 – insert i'm going to public void we call
01:09:22 – it insert arounds pearlies and now we're
01:09:27 – going to use our syntax we're going to
01:09:29 – PS insert and that's going to be
01:09:33 – equivalent actually when I can do an
01:09:35 – equal and apologize
01:09:37 – we're going to do set string and there's
01:09:43 – two values here okay
01:09:47 – the first value is what it's going to
01:09:53 – correspond to our sequel statement so
01:09:56 – it's going to basically look at it goes
01:09:57 – well what's the first thing it needs
01:09:58 – well for insert the first thing it needs
01:10:01 – is ID okay so we're going to say
01:10:06 – notice how it yeah I already figured out
01:10:10 – that we need to put an ID you notice how
01:10:15 – is automatically starting at the item
01:10:17 – type that in open its throwing an error
01:10:23 – but Sam what it's saying is that this
01:10:33 – might throw an error like what if what
01:10:35 – if there's an error in the sequel
01:10:36 – statement or what if there's a problem
01:10:38 – with the database yet remember whenever
01:10:40 – it's a warning about a possible
01:10:42 – exception
01:10:43 – it's a spot where the data is wrong you
01:10:46 – can crash the application and you never
01:10:49 – want that to happen so we're going to
01:10:54 – alt enter oh ok not there
01:10:58 – all right alt enter it again one of
01:11:05 – these times i'll actually get it right
01:11:07 – no suggestions thanks Ryan
01:11:13 – alright so we need to put in a try-catch
01:11:22 – that's what we're going to surround
01:11:23 – statement with a try-catch now they have
01:11:28 – this long little thing here that's just
01:11:32 – going to log the error but for our
01:11:35 – intents and purposes here
01:11:37 – I mean you can leave that basically what
01:11:40 – this will do is it wouldn't work and it
01:11:42 – would create a log entry on file the
01:11:44 – user would never see for our intents and
01:11:47 – purposes right now it makes a little bit
01:11:50 – more sense to actually i'll put it to
01:11:52 – the screen so we're going to do a print
01:11:55 – track stack trace if i can say it will
01:11:59 – do it right
01:12:00 – and that way we can see it otherwise it
01:12:03 – gets logged and log this is a little bit
01:12:05 – more elegant because you don't really
01:12:07 – want the user to know all you got a
01:12:09 – broken database here's your sequel
01:12:11 – statement that's off you know I thought
01:12:12 – that's irrelevant but you might put in
01:12:15 – some code that says sorry the database
01:12:17 – is unavailable currently try again in a
01:12:19 – couple of minutes or our programmers
01:12:22 – don't know what they're doing because
01:12:22 – they're still going to Gateway Technical
01:12:24 – College and figure it out until then
01:12:27 – good luck
01:12:30 – alright so now we're going to come back
01:12:32 – up here and we are going to type a
01:12:34 – series of these right and and and really
01:12:43 – you know i should do I should type it
01:12:45 – because what happens when you type it so
01:12:49 – what's going to be the next one
01:12:58 – yeah but we're using the database last
01:13:00 – name were using the variable last name
01:13:03 – apparently it's the variable
01:13:14 – and which one we are now too
01:13:23 – first time
01:13:41 – yeah i'm cheating
01:13:46 – after i get a little impatient
01:14:26 – no these are the variable name versions
01:14:28 – we created on this or in this file this
01:14:31 – is these are not the database names
01:14:48 – and that's all the statements
01:14:53 – the other thing we probably want to put
01:14:54 – here is PS insert execute update like
01:15:07 – that and then the other nice thing to do
01:15:10 – is put in a status equals inserted
01:15:17 – something like that something that makes
01:15:22 – sense if you want if you wanted these up
01:15:25 – exception areas you could do status
01:15:29 – equals something like that
01:15:40 – it doesn't work oh is that how you spell
01:15:46 – it
01:15:46 – oh how do you spell those things
01:15:54 – alright alright so you guys got insert
01:15:59 – so once you have insert guess how easy
01:16:05 – update is very easy it's almost
01:16:09 – identical
01:16:10 – thank you ctrl-c ctrl-v so we're going
01:16:17 – to call this one update in all these
01:16:21 – spots where we have insert here we're
01:16:27 – going to type update
01:17:03 – so I just had a little revelation as i
01:17:05 – was looking at this code here that we
01:17:08 – might have a little bit of an issue with
01:17:10 – these index number values because they
01:17:15 – need to correspond with the order in
01:17:17 – which the sequel statement itself is
01:17:19 – written so for example for insert ID
01:17:25 – comes first right
01:17:26 – 1234 r0 12345678 right and then we wrote
01:17:34 – this it follows that same pattern when
01:17:37 – we do an update though how we what
01:17:44 – orders the data in 0 1234567 ideas eight
01:17:54 – right so you have a little adjusting to
01:18:03 – do here that was update right so ID is
01:18:10 – eight last name is 0 1 2 etc
01:18:18 – otherwise you'll be like why is your
01:18:22 – chocolate in my peanut butter right yeah
01:18:28 – it's never been a problem but you don't
01:18:32 – want your email address going in the
01:18:34 – phone number field basically you know
01:18:39 – you would figure this one out if I
01:18:41 – didn't mention it yeah what would happen
01:18:44 – to be like why is that happening
01:18:46 – yeah because wherever we're putting
01:18:51 – those those question marks we have to do
01:18:53 – some stuff all right so the last thing
01:18:56 – that we have to write as the view so
01:19:01 – let's go ahead and create least the
01:19:02 – beginning for that or home stretch here
01:19:09 – alright what I'm going to do here in
01:19:15 – what I've done in the past then because
01:19:16 – i'm copying from my old code i was
01:19:18 – telling you guys know that I'm going to
01:19:22 – a print line to the console and what I'm
01:19:25 – going to output is the ID and the reason
01:19:29 – I'm doing this is I want to see what
01:19:31 – ideas printing out for outputting are we
01:19:38 – getting in other words are we getting
01:19:40 – the right one
01:19:41 – alright so after we do that we're going
01:19:46 – to write a prepared statement going to a
01:19:47 – PS view and that's going to be or
01:19:55 – actually going to set string and we're
01:20:04 – going to pull back ID right
01:20:06 – yes that's what we're doing alright so
01:20:13 – we're gonna pull back ID and you know
01:20:19 – keep in mind that you know there's a
01:20:22 – field order here so we're trying to like
01:20:24 – stick with that and then we also want
01:20:31 – because we're going to be actually
01:20:33 – pulling back a query remember and we did
01:20:36 – this in the the database chapter we're
01:20:39 – going to pull back a result set i'm not
01:20:41 – sure why that ended up down there must
01:20:42 – hit the wrong key
01:20:43 – so we're going to do a resultset I don't
01:20:48 – know what we call it just thought result
01:20:54 – and apparently this needs a library
01:21:05 – what is not liking here
01:21:10 – ok so once again this once a try-catch
01:21:15 – going to alt enter
01:21:26 – and once again i'm going to use the the
01:21:28 – print stack trace and my all message
01:21:32 – mean you can always stick with what's
01:21:39 – there and really I didn't want this all
01:21:43 – the way down here I want it to be right
01:21:46 – after that statement so that's where i'm
01:21:47 – going to put it want to be that
01:21:58 – yeah well I haven't finished statement
01:22:02 – alright so we're going to PS view that
01:22:07 – execute query somebody tell me what this
01:22:13 – is going to do
01:22:24 – based on the idea that were thrown out
01:22:26 – exactly right so
01:22:45 – years old there's a little bit of coding
01:22:47 – going on here
01:23:01 – why it's thrown something in there are
01:23:03 – automatically so i could either call the
01:23:06 – column name if I know what the name of
01:23:09 – the column is or the column index value
01:23:12 – the column index value for last name is
01:23:20 – one right
01:23:27 – and really what's going to happen here
01:23:29 – we're just going to have this is going
01:23:31 – to be a repeating process it this is
01:23:33 – worthy of copy-pasting so this is going
01:23:37 – to be first name
01:23:40 – that's column 2 and I i'm jumping back
01:23:45 – to the database here you guys because
01:23:48 – here we're looking at the staff table
01:23:51 – just going to log back in
01:23:59 – is that there is
01:24:10 – oh yeah now i'm seeing a problem here
01:24:15 – yeah i'm seeing a little bit problem
01:24:17 – here
01:24:18 – yeah there's no 0 so all the numbers
01:24:24 – that we put in so far we're going to go
01:24:26 – back and we're going to adjust them all
01:24:29 – by one number it's a good thing I look
01:24:32 – because it just popped in my head I'm
01:24:34 – like all right
01:24:36 – the database starts counting the ID
01:24:38 – numbers at one so you guys ready for
01:24:41 – this
01:24:42 – all of them must be increased by one if
01:24:52 – you guys find this tedious might want to
01:24:54 – consider different career paths boy you
01:24:58 – know if you guys are sitting down and
01:24:59 – playing a video game that was really
01:25:01 – tedious to try to get through a level or
01:25:02 – something you guys would be at it all
01:25:04 – night long until you got it I don't know
01:25:06 – why programming should really be any
01:25:07 – different
01:25:08 – I am so glad I got that otherwise have
01:25:14 – you getting like 20 emails and copier
01:25:17 – code it doesn't work
01:25:18 – actually I would copy my code and it
01:25:21 – wouldn't work so and how do we validate
01:25:25 – that well let's just look see right
01:25:29 – there
01:25:30 – alright so we caught those we caught
01:25:33 – those this needs to be a one and so last
01:25:43 – name will be to first name will be three
01:25:51 – and really you know the part that i'm
01:25:52 – gonna copy paste this last part
01:25:54 – so the next thing that comes is middle
01:25:57 – initial
01:25:59 – that's a 4 address
01:26:24 – state
01:26:34 – we call it phone here is that we called
01:26:36 – it
01:26:48 – find out in the sack and email
01:27:01 – ok if there is no next item we will do
01:27:10 – an else and really gonna do up an output
01:27:21 – to the console did this in the past for
01:27:26 – a reason and we could also do a status
01:27:30 – message
01:28:04 – and if you guys want to be funny
01:28:07 – there should be humor
01:28:23 – ok
01:28:27 – you can be fun
01:28:44 – and by my estimations that's all we need
01:28:49 – to do
01:28:59 – I'm just checking all these numbers
01:29:00 – again
01:29:11 – in for which thing
01:29:20 – no no me what we're doing is we're we're
01:29:25 – pulling in from the form and then this
01:29:30 – is taking that information putting it
01:29:32 – into the query string and then the
01:29:34 – prepared statement sending it off to
01:29:36 – execute not really
01:29:43 – yeah that's a good point get status
01:29:46 – really doesn't need it but it doesn't
01:29:47 – hurt that they're there
01:29:49 – yeah getters and setters for that one
01:29:52 – oops
01:29:58 – alright I think we're good now comes the
01:30:04 – brave part see if it works I have these
01:30:10 – two libraries here that our flag and I'm
01:30:12 – removing them i'm looking for other
01:30:16 – underlines highlights little light bulbs
01:30:20 – on the side like this
01:30:27 – it should be removed alright well i'm
01:30:30 – leaving it there so it should be but
01:30:34 – it's not going to be our I'm saving it
01:30:39 – my index file seems to be saved
01:30:43 – Kenny anybody anticipate in advance any
01:30:46 – problems we might run into now I i don't
01:30:53 – know i can't think of any ahead and play
01:30:57 – all right
01:30:59 – yay yeah alright so notice the error
01:31:10 – that we're getting it says index that
01:31:14 – HTML XHTML it says at 1955 why 19 column
01:31:23 – 55 the value staffed at first the class
01:31:28 – staff does not have the property first
01:31:31 – ok let's go back and take a look
01:31:37 – why 19c little flag here first name
01:31:49 – alright let's try it again
01:31:54 – yeah at least it's showing up now
01:31:56 – whether it works or not that's a
01:31:57 – separate story
01:31:58 – alright so the way this is best gonna
01:32:03 – work is take a look at your database and
01:32:06 – look at the actual contents of the
01:32:08 – database i'm going to browse mode on it
01:32:10 – and i see that i have somebody with an
01:32:12 – idea of 111 and one with 22 so real
01:32:16 – logical thing for us to do that is to go
01:32:19 – back to the browser and type in 111 and
01:32:25 – view
01:32:26 – ok I you see I'm not going into panic
01:32:32 – mode here we just have to tweak your
01:32:34 – code right but it says java language
01:32:37 – nullpointerexception this is where when
01:32:40 – you put in those little system.out.print
01:32:42 – lines i'm going to go back to NetBeans
01:32:46 – now and I'm going to look down here and
01:32:49 – I'm going to see if there's any console
01:32:50 – messages that are telling me what's
01:32:52 – going on
01:32:54 – yeah the bill was successful
01:32:58 – yeah so you see all the little outputs
01:33:06 – that are happening here
01:33:12 – got all sorts of stuff going on
01:33:19 – so this little button so I really what I
01:33:26 – want to do is I want to look at the one
01:33:28 – that's that's the culprit here ones that
01:33:38 – are in Java libraries there's nothing I
01:33:39 – can do about those ones i can do
01:33:41 – something about are things like this so
01:33:47 – it says staff dot view so it's only the
01:33:51 – method 186 so it's pointing to so i can
01:33:59 – actually you know honestly I can click
01:34:01 – on this it will take me right there so
01:34:04 – it's not liking this
01:34:06 – this psu set string ID my gas is there
01:34:15 – something about the index value that's
01:34:18 – still not quite right now
01:34:28 – yeah i'm gonna here's what i'm gonna do
01:34:34 – i'm just a real primitive level i'm
01:34:37 – gonna stop the the database server i'm
01:34:41 – going to restart it not i'm sorry the
01:34:44 – web server
01:35:06 – alright you can watch all the server
01:35:07 – logs running here so you see all the
01:35:09 – things that's doing in the background
01:35:15 – ok so here it is waiting for stuff to
01:35:19 – happen and I think it's just about ready
01:35:22 – to go
01:35:23 – ok alright so before we run into any
01:35:31 – issues
01:35:38 – I don't think that these are causing any
01:35:40 – problems right I think we need to run it
01:35:45 – again and take a look at the output
01:35:47 – ok so one more time alright I'm going to
01:35:55 – go back and look at the server logs just
01:35:57 – from doing that
01:35:59 – ok so the application seems to be
01:36:01 – running ok but right off the bat notice
01:36:04 – how there's already exceptions happening
01:36:06 – and the server
01:36:08 – alright so this is where we left off
01:36:15 – notice it says severe that's really
01:36:21 – enticing and it says for the first
01:36:25 – problem we have here see right here
01:36:28 – first problem we want to find the first
01:36:31 – one and that's line 113 line 108 let's
01:36:43 – look at those two first so wyd 113 108
01:36:46 – so 108 is the init database
01:36:53 – I don't see what a problem would be with
01:36:55 – that then 113 113
01:37:06 – I'm going to pause for a second let you
01:37:09 – guys figure it out
01:37:10 – alright so i put up the little
01:37:13 – challenger see people could figure it
01:37:14 – out and somebody finally did that its
01:37:17 – flagging lines 108 and 113 notice here
01:37:22 – it says the system completely different
01:37:26 – but basically what's happening is we
01:37:31 – never added the driver 24 to connect to
01:37:35 – the database that can connect to the
01:37:36 – database we can't do any of the database
01:37:38 – stuff at all so the question is how do
01:37:41 – we do it
01:37:42 – see these three tabs up top here just
01:37:47 – one called databases
01:37:49 – yeah there there's these three tabs up
01:37:54 – top here project files and services and
01:37:58 – then notice that we have some stuff here
01:38:03 – now I have it I kind of have a little
01:38:05 – bit of an issue here as well because i
01:38:09 – have my sequel local on my machine
01:38:12 – notice javas got its own database
01:38:15 – there's drivers but we need to get this
01:38:21 – connecting up so that this will work so
01:38:29 – i try to connect thing you think
01:38:35 – what's my username what's my password i
01:38:39 – know my password
01:38:41 – yeah so it doesn't know how to connect
01:38:45 – is what it's telling you
01:38:47 – even though we have this stuff here
01:38:48 – let's connect
01:38:52 – yeah so you see what it did
01:38:59 – yeah a lot
01:39:02 – let's give it a try now going to hit
01:39:08 – play again
01:39:11 – ok so I came up in my other window here
01:39:14 – only just pull it over
01:39:15 – oops ok so now
01:39:23 – yeah right
01:39:34 – yeah it still doesn't like this
01:39:39 – particular line here
01:39:41 – alright so this is our next thing to fix
01:39:45 – that took us because we last time we
01:39:51 – looked at the bottom here at least we
01:39:52 – got rid of one of the errors so now
01:39:55 – we're back to some of this other syntax
01:39:58 – here
01:40:05 – yeah and I i have a suspicious what is
01:40:08 – this is line 186 in view
01:40:21 – you can see I'm we totally
01:40:24 – double-checking my code syntax here
01:40:41 – I'm gonna run this again
01:40:47 – wasn't that interesting ready to come up
01:40:50 – the area internet explorer thank you
01:40:51 – know all right
01:40:56 – wow it is there we break something
01:41:00 – yeah it does look different all


Video Url:
http://youtu.be/IoPEnJzFu4s

(Visited 310 times, 57 visits today)

Comments

comments