Hey there.
So alerts continue implementing the methods of our database handler class and now we are implementing
a method with which we will get all the records from our table public.
This method will return not one car object but a list of objects we could specify here.
Read at least and here the car objects and called this method get all costs
but I'm not using my rails here.
I use the least as the return value least is an interface or the jar and array release class implements
this interface.
If we go to the Oracle platform or we can see here in the least of all classes I will say that the interface
is here too.
We can.
In the letter l find the least interface which is located in the Java Uta package and here his description
is description here sees all known implementing classes.
Although no one classes implement and this interface here it says released Linked List stack vector.
There are a lot of different structures that implement this interface.
Why I'm using the interface here.
The interface needs to be used because for example now we can use in the method released inside the
method and it returns on that released object but in the future maybe we will want to use in our application
in the same method.
Some are either of these linked list or vector and then we will need to redo the method and all the
code associated with this method which will take parameter specifically.
These are released it will be necessary to redo everything.
This is a big joke but when we put a generalized interface here we can safely use board released or
linked list or any other class that implements this interface.
And since this class implements this interface we can return an object of this class and everything
will work correctly.
This is a kind of abstraction.
And here we ride Esko like that at base D.B. these we will read the records so get a readable database.
And here we will create an interface variable least which contains objects.
Car let's name costliest for example and assign you array lists.
Well now we create a three in which we place our high school code name and select all cost and assign
the following values we write in capital let us select and then specify our series.
This means that we select everything.
Then the keyboard for all and concatenate with the name or the table from which we will select all records.
We take this well remove.
We take this name from our you to table name.
Then we create again an object or the cursor class and assign D.B.
or query.
There is such a method.
And here we write.
Select all class 0 3 and quit.
Good.
And the second argument specify no.
Next we write the following quote Eve cursor move to first method move to first returns true if the
cursor contains any records.
And then in this case we will do the following.
We will write a do while loop and we will execute this loop while
cursor move to next.
While there is the next element in the cursor and further in the loop as long as there is the next entry
in the cursor we will create a new object of class car.
Son new car.
And now we can use our cities to set the field value.
Car set I.D. ideas you remember.
In type.
Therefore we need to recognize it as integer since it is a string in the cursor.
And here we are right.
Cursor get string and zero column index No.
So we will set the remaining fields of our object car cost me.
Here we will write simply cursor gets three scenes.
These fields are in the object of class car.
All right it's three and he will ride one.
And car said Bryce cursor gets three and two.
And of course now we have to put this object in cars at least we are right cars least at car
and after the loop when our lease is filled with objects extracted from the cursor we can return this
list from the return from the method return cast list.
Now let's check the functionality of our methods.
Let's go to main activity and create an object of class database handler in all create method let's
call it database handler and assign a new database handler.
And here we have to pass the context.
Let's pass these and let's add entries to our database.
Let's make the first record.
Toyota for example.
And thirty thousand dollars.
We will use our method.
Add to Cart to add we share it in which we must pass an object of class car.
And so we write that a base handler at car.
And here we will create a new object older cock loss new car
and let's use the constructor with two parameters.
Name and price.
As I said when adding to the database the idea is added automatically and incremented by 1 which each
with each new record.
That is we arrived here from the beginning.
The name Toyota and second best the parameter.
Thirty thousand dollars.
Similarly let's add a few more entries let me copy everything for speed.
Here we write.
Let's open.
And twenty five thousand
yeah.
Let it be merciless
fifty thousand.
And Kya
twenty eight thousand.
So here we have added four interests to our database.
Our application will not display anything on the phone screen for now we will use our low cut to see
that our the basis of working.
So as you as we add four car entries to the database now we can create at least
Car objects.
Let's call it the car list and assign the value returned from the get all cars method.
Now get all cars method returns all records about cars contained in our database in the form of at least
that is we can write database handler get all cars and now we can.
In our low cut we can see what is in these columns.
Let's pull alerts in loop displayed car car from car list.
We will write in log log the
then we write car in for for example information about the car.
And then we pass here.
The next I.D..
Plus car.
Get I.D. further concatenate with name.
It's not protocol here.
It's not necessary.
It just put spaces.
Plus car.
Get name plus
Bryce
plus.
Car get Bryce.
And so we created an object or the database handler cost.
Then we added records about the cars in the database through these object.
Then we created a new list and retrieve all the records from our database again using their database
handler.
In these lists and we display in the log everything that is in this list everything that we extracted
from the database.
Let's open more cut and run the application
here.
Let's specify these information.
The key here was select the bark mode and as you can see a list of four entries is displayed and IED
as you can see is assigned sequentially starting from 1 and then the D increase by 1 with each record
added.
Let's put a few more records and see if these the records are erased or added to those that were let's
call it it's code pasted and here for example indicate Mazda
Honda
scroll the
from Di.
Let me also remove this space here because nothing.
These are boarded by the space and restart.
You see we have eight more interest added that is we had four but it became twelve a new record.
Even if the contents in it is the same as in the previous records is added on the new I.D. That is a
record with different ideas may contain the same information.
This is normal for that database.
So we see 5 6 7 8 record.
Add these Toyota Opel ambassadors and Kia Ikea and then four more new cars that we added later.
Well we have created a database.
We learn to add information to it and also extract and in the next video.
We will continue to get acquainted with working with the database.