Hey there.
Let's continue the development of our database now we need to create functionality for their corrupt
operations so-called what it is corrupt means.
The first word great.
The second I read the next update.
And the next.
Delete this.
This is the abbreviation crud that is we need to create functionality to create read update and delete
records from our database.
Let's do it let's first create a public void ad car
method with which we will add a record about our car to the database in our table and further in this
method we need to first get the object or database this line database let's call it D.B. and assign
a value using the following code.
These get I'll write about database that is you'll see that all get readable and the bottom get to write
about database when we want to write something to the database we need to use get right about database
when we want to reads something we must use get a readable database accordingly and that is in this
case we specify the second test to get right the ball database and next reuse glass content values in
order to interact with our database.
This is a site on abstraction using their value and key players like in hash map or intent you can interact
with database we write content values calls our object also content values and assign new content values
and then we must put the key value Pearce in it content values put and we need took place in the content
values record about the car to do this we need to use an object or the car type gloss the model that
we created these CLOs and let's pass such a parameter this object that is ad car and here we specify
Car Car Next we specify the key using the you took loss you to key name and then from this object we
will extract the value using the getters and setters that we created here we have a method get name
that is we can put the name of that car by linking the key of the column name key name that is specified
here
and associate this key with the value extracted from the object car car get name and the same we do
for the second column price that is we are right content values put you to key price and then the object
car get price as you noticed we don't put an I.D. in the content values because the idea in Esko life
database is added and incremented automatically and now we have to insert the created record into our
database.
This is done as walls right.
D.B. this object that we created here and right insert and then the first parameter the name of the
table in which we will insert utility table name next object next parameter sorry null come hack we
assign now now and the next parameter is content values or words specify them and after we put the area
code we need to close the database connection using the following method Debbie calls so we created
a method for portraying records in our database table.
Well now we need to create of course the method by which we will extract the rackets.
Please do this.
Public right now.
We will not have award method but a method that returns an object of class car seats.
We have objects of class car in our class get car and we will retrieve the record of our car by I.D.
since each I.D. in the table is unique.
There are no two identical I.D. in one table.
Therefore using the I.D. we can extract one specific record we need from our table.
Therefore as a parameter we will pass the I.D. here.
Next we have to create the object s light database but now get readable database since we will read
data from our database.
That is we write Cisco like database D.B. and assign these get readable database and then we will retrieve
the array codes using that car subclass which will allow us to navigate through the data in the database.
And so we write code so call it cursor and assign our debt and D.B. database and the query method next.
We must pass the table name you to not table name put a comma then we must create and use three and
create an at least all the columns of value of which we want to extract.
We write you two key ideas the first column The New Deal can name then you do keep rice
and after that put a comma the next parameter that we must pass is our I.D. by which we will retrieve
the record that is you do key idea we write and concatenate with such a form of record equals and equation
side.
Using these constructor construction we request from the table a record from this column for The key
idea column and we specify this with an equal sign an equation.
Next put a comma again and we need to create and not a sprinkle right.
And here the full value is listed.
We need string value all and specify the I.D. which we pass as a parameter.
All right.
The idea that is there will be in this array.
There is only one value.
We trust the remaining parameters.
We'll be not
let me transfer it so that it is better to see that there are four parameters grew by having order by
ending it.
We'll figure it out later.
Until just now we just pass all knowledge here.
So again we retrieve the record from the database using the query method.
For this we first specify the name of the table from which we want to extract data.
Then specify the array in which we specify the value from which columns we want to extract.
We can specify all the columns as we specify here I.D. and name and price.
That is we extract all the values in this write up or we could indicate only the name or only the price
or honor that the order name and price.
And then we would need to specify only the corresponding columns.
Next we indicate selection.
That is the selection is being a by a deep column which we pass here in the next array decided which
is obtained as a parameter in the method.
Well the fuller parameters we set to now because at the moment we are not interested in any sorting
selection by some criteria.
Next we must indicate the following.
We must check if cursor not equals null
and then we write cursor move to first goal method and now we can create a car object which we will
return and extract information from our cursor to eat the right car.
Car son new car and we use the full constructor.
This one here in which there is an I.D. and name and price parameters.
We will pass them here from the cursor we write cursor.
Get three can specify zero here.
Then put a comma but since we get the string here in cursive we need to recognize this drink as in integer
seats in our car object.
This field is of the type.
Let's pass these values here.
You see in the constructor car we have an integer parameter
next we extract the falling curve so get string 1 and 1 what parameter
let's move.
Here cursor gets 3 and 2
and that is our table with the 3 columns and index in diocese or the column starts from 0 0 call inside
the first name and the second prize.
Here we indicate then in diocese of follow columns column index SCC 0 1 and 2.
That is we extract all the information from our record and put it in the newly created car object which
we return at the end.
Upon return car and so we get the desired object by I.D. which we pass as a parameter in the get column
method and in the next we do.
We will continue the implementation methods of our database.