In this example we’ve learned about prepared statement as you can see on line number 16 we have declared an object of priests prepared statement type as opposed to statement type which we have been using in our previous examples the prepared statement object allows me to write an SQL statement which is not 100% done but will have some missing.
Components which will be filled in during run time for example I need to write an SQL statement where I need to accept the start ID and the end ID of all.
The employees so that I can grab only those employees that fall within that.
Range I can’t do that with a statement object because statement object requires es field to be completed ahead of time prepared statement.
Allow me to complete mask you’ll student during runtime so prepared statement is what I’ve used here so if you look at my line number 23 I wrote my select statement select star from employees where employee ID between under Road two sets of question marks these question marks will be filled in during runtime so what we have done.
Is we have declared two variables start ID and.
An ID we’re accepting their values from user this is something with being learned in previous classes how you accept an.
Input from user from the console and then we start replacing the question marks with the values so all the question marks are automatically sequence so the first question mark will be one the second question mark will be two so that’s what I’m doing I’m putting one and I’m putting start ID so start ID will actually go in place of one in the s dmt which is.
My prepared statement object and number.
Second question mark so end ID will gonna go in place.
Such a second question mark in the SpMT which is method prepared statement object then just like with the statement object I can call execute query with a.
Preferred statement object I can also call execute query the result will be stored.
In result set and I can then convert through the result set and display the output so there are some other components.
Of this example which are going to explain in the next part but in this part I only taught wanted to talk about the prepared statement let me demo this example so when I run this example it asks me for a start employee ID and an end employee ID and here you.
Go it gives me all the employees only between the start and the end how I’m doing the column.
Representation and how am i pulling in the field and their names from the database we’re gonna be looking at some metadata stuff in our next example which will help you understand how we are doing that.
Component as opposed as far as the placement and.
Columns is concerned this is something that you learn in our previous classes where we talked about system dot out dot print app system dot out dot print app as opposed to println this is where you can give a % S which represents a data type 20 is the column size and a negative sign represents left-aligned and I am putting pressing.
Tab between each of the columns so what are you learned in our previous classes you have to use your result set object to get string or get date or get double and it can.