I am using this 1st query still cannot achieve what i want:
PreparedStatement id = con.prepareStatement("select c_id from customer where c_name=? ORDER by c_name desc ");
id.setString(1,m.getName());
I have a JSP form which is filling the (MySQL)customer table and c_id
is only auto-incremented when the form is submitted on button click, but on submission, I want to do another thing which is to select latest entry of c_id which is filled in the table. Due to submission of an entry, a new auto-incremented c_id has been generated which I am getting through this query which is alright.
PreparedStatement id = con.prepareStatement("select c_id from customer where c_name=? ");
id.setString(1,m.getName());
Now the problem is that the (1st or 2nd)query gets the c_id
by looking at c_name
, if the c_name
was never present in the table and has been entered the first time then it will surely get the latest c_id
by looking at c_name
, but what if the c_name
was already present.
For example:
If customer has c_id
10
and c_name
jacob
and if I entered the query for the first time I am able to select c_id
10
but now if I try to enter another entry having c_id
11
and c_name
jacob
I still get the c_id
10
here and here what I want is c_id
11
which is latest entered having same c_name
.
Is there any way to do this?