Hello and welcome to the kulang programming language course, in this case, we want to create a function
to insert a new student in student data in person database.
So go to the DB connection and create new fonts.
First, define the function, then save that accept student object as parameter.
And if the addition of a student to the database is done correctly, the idea of the last added the
student will be returned as return time.
So right func save and set a student as the parameter to the model that student
and cert and 64 as return type value.
Now, Colin Connect function for initializing minus driver name and data source name.
This function returns a DB object from a school package, which gave us access to methods contained
in that package to perform crowd operations, so define a value there like DB Collins equals and calling
connect function.
We use Ether for closing the creator DB object ether.
Do you buy the clothes after creating a DB object, the inventory parameter that creates a prepared
statement for later queries or executions, multiple queries or executions may be run concurrently from
the return, the statement.
The caller must call the statements close method when the statement is no longer needed, this function
returned to value.
First is Santa object from a school package that is a prepared statement and the order is error.
So first, define two variables like save and say comma error column equals and calling pretty parameter
to prepare and write suitable query for create a new object insert
into the student.
Said variable of a student I.D. name and age
values.
Sit question mark instead of variable values.
We set three question mark because we have three fields
check every status.
Now calling execute method from a secured package and executes a prepared statement with the given arguments
and returns a result summarizing the effect of the statement, this method returns to values first and
object of result inner faith and the other is error object.
So we defined two variables like resolve and row resolved comma error calling equals and calling exec
method on the same object say dark ExAC method and set.
A student feels as arguments instead of question marks included statements sequentially like student
debt, IED
and the student, the name
and the student age.
Check it or a status.
Now calling last inserted I from front cured package that returns the integer generated by the database
in response to a comment publicly, this will be form and alter increment column, then inserting a
new rule.
This function returns to values first and in CC for value, and the other is error.
So we write two variables like student I.D. and the rule the student's
I.D. Common error coloring equals resolved start last user I.D. and check notice the.
Was
that the rule?
Now, sit a student ideas writer and type of save function writer student Spike Lee format the cold
and save the project.
Now we could define the function name safe that accept a student object as parameter and save it as
a record into the student table in person database and returns the idea generated of the added new record
by database.
Now it's time to go to the main function to use this query statement.
Go to the main function and clear the last code.
In this case, we want to save a new student and person database, so we should use from save function
from TBE tools that accept a student as input arguments and returns, either that person like so first
create and a student object from a student strike and initialize it.
Define a variable like a student column equals model dot student and initialize it I.D., for example.
Seven.
Name, for example, Robert and Age, for example.
50.
Now, you would say function from DB tools.
Pichai's and St create the student object as are doing this to eat first.
Define an integer variable for return value of the function last insert i.
The column equals DB tools, dot save and post a student as arguments to it
and display the last insert I-T.
Last year there two I.D..
Reformat the court, save the project and execute the program go wrong.
It's like a slush main that's made that glue.
Now we can see the output, the new student is a sort quietly in student table in the person database
and new student ideas return.
We can go to my school database and see these changes.
First, create a new query type.
Go to the database use person and create a select query sending Mr. Brown.
The student and execute the query, we could see the newest student is a stone chronically in database
87 seven named Robert and age 50.
OK.
In order not to prolong the time of decision, we will finish you and we will continue the content in
the next session.
Goodbye.