I want to get the ID of the last row inserted for "kashif".
How can I do this in Java?
I have a database table with columns:
___________________________________________________________________________
| id | name | card_number | cell_number |sms_verification|inserted_date_time|
id
is set as the primary key with auto-increment.
Inserting data into the database via Java works - I have a class where I get input from the user, and in the same class, I'm making a connection to the database.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection connection = DriverManager.getConnection(
"jdbc:sqlserver://localhost;instance=MSSQLSERVER;databaseName=RestApi;user=sa;password=coder182");
Statement statement = connection.createStatement();
String query = "insert into User_information(action_name, card_number , cell_number ,sms_verification , inserted_date_time)"
+ "values ('" + action_name + "','" + card_number + "', '" + cell_number + "' , '" + sms_verification
+ "', '" + now + "');";
statement.executeUpdate(query)
Inputs look like this:
kashif,28028209,239203084,yes
abid,233000,6260616,no
kashif,28028209,239203084,yes