Getting the last inserted id using jsp

Getting the last inserted id using jsp

Pls how can i retrieve the last inserted id after submitting a form to mysql using jsp

View Answers

November 17, 2011 at 3:26 PM

1)form.jsp:

<html>
<form method="post" action="insert.jsp">
<table>
<tr><td>Name:</td><td><input type="text" name="name"></td></tr>
<tr><td>Address:</td><td><input type="text" name="address"></td></tr>
<tr><td></td><td><input type="submit" value="Submit"></td></tr>
</table>
</form>
</html>

2)insert.jsp:

<%@page import="java.sql.*,java.util.*"%>
<%
String name=request.getParameter("name");
String address=request.getParameter("address");
        try{
         Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/roseindia", "root", "root");
           Statement st=con.createStatement();
           int i=st.executeUpdate("insert into data(name,address) values('"+name+"','"+address+"')");
           out.println("Data is successfully inserted!");
           int id=0;
           ResultSet rs=st.executeQuery("select * from data");
           if(rs.last()){
               id=rs.getInt("id");
           }
           out.println("Last inserted Id: "+id);


        }
        catch(Exception e){
        System.out.print(e);
        e.printStackTrace();
        }
        %>









Related Tutorials/Questions & Answers:
Getting the last inserted id using jsp
Getting the last inserted id using jsp  Pls how can i retrieve the last inserted id after submitting a form to mysql using jsp
JDBC: Last Inserted Id Example
JDBC: Last Inserted Id Example In this tutorial, you will learn how to find last inserted record ID using JDBC API. Getting Last Inserted ID : Last... insertion.  you can get the last inserted id by using MAX(), writing
Advertisements
Getting the ID of the element that fired an event using JQuery
Getting the ID of the element that fired an event using JQuery  Hello sir I want to know-Is there any way to get the ID of the element that fires the event? Please mention the code with your reply. This will make easy for me
value is inserted into the sql table through jsp-jdbc but not getting stored into the data base,only row is increasing.
value is inserted into the sql table through jsp-jdbc but not getting stored into the data base,only row is increasing.  <html> <..."> <title>JSP Page</title> <style type
To Display the 'Last Modified' message in JSP
To Display the 'Last Modified' message in JSP  I have to display the "Last Modified" auto save message in a portlet page at the right end corner using JSP I have used this below coding but I'm not getting the solution can anyone
Retrieving newly inserted records and displaying in jsp forever
Retrieving newly inserted records and displaying in jsp forever  Sir... a table and display in jsp(Each row contains a field called as "session... of every record which is displayed on the jsp (not in database) and immediately i have
Insert text into database table using JSP & jQuery
Insert text into database table using JSP & jQuery In this tutorial , the text is inserted into database table using JSP & jQuery. In the below... using "fadeIn" effect. The second JSP page contains code
ID using get the databse latest value and displayed in jsp
ID using get the databse latest value and displayed in jsp   I have... in the form (it means latest values) ... how to retrive that values using ID... in preview jsp page. the id will shown in end of the url also
ID using get the databse latest value and displayed in jsp
ID using get the databse latest value and displayed in jsp  function... want to get the latest value using id and displayed in that start date end date etc,... How to get latest values in my jsp page and id will be shown in url
the last data entered into database is getting stored again after refreshing
the last data entered into database is getting stored again after refreshing  hey all i made a shout box using php and mysql but the last data... if the data is deleted from the database the last data entered is getting posted plz help
JSP Getting Started, Getting Started With JSP
Getting Started with JSP This page is all about getting started with JSP language. Java Server Pages or JSP for short is Sun specification for developing web applications using Java technologies. The JSP allows the developers
Getting an exception - JSP-Servlet
Getting an exception  sir i used u r code for sending a mass email by reading an excel sheet,but i am getting a following error so please help me...(HSSFWorkbook.java:2 98) at org.apache.jsp.jsp.TestMailApproval_jsp._jspService
Getting an exception - JSP-Servlet
Getting an exception  sir i used u r code for sending a mass email by reading an excel sheet,but i am getting a following error so please help me...) at org.apache.jsp.jsp.TestMailApproval_jsp._jspService(TestMailApproval_ jsp.java:94
Getting an exception - JSP-Servlet
Getting an exception  Dear sir,while executing this code i am getting... org.apache.jasper.JasperException: An exception occurred processing JSP page /jsp/newTestMES3.jsp at line...: java.lang.Character org.apache.jsp.jsp.newTestMES3_jsp._jspService(newTestMES3_jsp.java:128
dynamically created links id from mysql table is not getting
only getting the last recordset from table malayalamcinema, plz help me, its...dynamically created links id from mysql table is not getting  guys... to another page, but while i'm trying to access its value, i'm getting only
Getting an exception - JSP-Servlet
Getting an exception  Dear Sir , While sending a mail am getting an following exception javax.mail.MessagingException: 554 mail server permanently rejected message (#5. 3.0)so how to over come from this please help
JSP Tutorials, Getting started with JSP
Getting started with JSP The JSP getting started tutorial will help you... technology for developing the dynamic web application using Java. JSP is good... you in getting started with JSP
Getting an exception - JSP-Servlet
Getting an exception  sir i changed to that ie InputStream myInput1 = new FileInputStream(fileName); HSSFWorkbook myWorkBook = new HSSFWorkbook...) at org.apache.jsp.jsp.ReadExcelFile_jsp._jspService(ReadExcelFile_jsp.ja va:70
Getting an exception - JSP-Servlet
Getting an exception  thanks sir for u r reply ,but i already added that jar file sir even though i m getting an exception sir please help me sir ... thanks in advance..  Hi Friend, You can do one thing, replace
Not getting the logic - JSP-Servlet
Not getting the logic  there is one sub module in my project.In that it display the list of candidates in a grid table who are selected for the interview with inline edit and the field of the table contains one checkbox, e.g if 5
Getting an exception - JSP-Servlet
Getting an exception   sir i am Getting following exception when executing javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/apache/poi/poifs/filesystem/POIFSFileSystem I have used ur code import
Getting an exception - JSP-Servlet
Getting an exception  sir i m Getting an following exception while sending a mail with attachment value ofsession is javax.mail.Session@192d604 value of mimemessage is javax.mail.internet.MimeMessage@120b2da value
How to store data entered in JSP page by a user in XML file & later retrieval of data using id at other page
How to store data entered in JSP page by a user in XML file & later retrieval of data using id at other page  I have made a form in JSP having emp id... in another jsp page using retrieve submit button.Please tell step by step instructions
Getting a Property value in jsp
;Getting a Property Value</H1> <jsp:useBean id="bean" class... Getting a Property value in jsp   ..., we are using bean with <jsp:useBean> tag. <jsp:getProperty> tag
Getting file size - JSP-Servlet
Getting file size  Hello friends, I am doing a jsp project... type information from JSP Request Header String contentType... Uploading in JSP Choose the file To Upload
Getting ResultSet size - JSP-Servlet
Getting ResultSet size  Hello friends, what is the result getFetchSize() of resultset. I got error with this method. While rs contains three rows it returns 0 . Please help me.  Hi friend
<%=request.getHeader("referer")%>,getting null in jsp - JSP-Servlet
,getting null in jsp  Hi, I am getting null in in jsp.Could you help on this regards. Thanks Ajay   Hi friend, Code to help in solving the problem : Thanks
getting values from database - JSP-Servlet
getting values from database  I tried the following code abc.html aaa.jsp I am not getting exceptions now. But I am not getting output also. Plz help.   Hi Friend, Run your
delete row using id
delete row using id  package pkg2; import org.hibernate.Query; import... = "delete from Insurance insurance where id = 2"; Query query = sess.createQuery...()); } } } this is the code m using . Error is -query must begin with SELECT or FROM
Getting Null pointer Exception in the jsp page
Getting Null pointer Exception in the jsp page  I have developed this jsp page to store the data in database.While storing the value of check box in database I am getting null pointer exception in the following code
Getting Null pointer Exception in the jsp page
Getting Null pointer Exception in the jsp page  I have developed this jsp page to store the data in database.While storing the value of check box in database I am getting null pointer exception in the following code
Getting Null pointer Exception in the jsp page
Getting Null pointer Exception in the jsp page  I have developed this jsp page to store the data in database.While storing the value of check box in database I am getting null pointer exception in the following code
Getting Null pointer Exception in the jsp page
Getting Null pointer Exception in the jsp page  I have developed this jsp page to store the data in database.While storing the value of check box in database I am getting null pointer exception in the following code
Further advice needed on my last question - JSP-Servlet
Further advice needed on my last question  Dear Experts, I refer to your last solution regarding my matching codes. After I tried out your...:\Documents and Settingsapache\jsp\enter_jsp.java:132: ')' expected } catch
Difference between getting a document using DOMParser & DocumentBuilderFactory !!!
Difference between getting a document using DOMParser & DocumentBuilderFactory !!!  Hi, In DOM tutorials, on one page a document is formed using DocumentBuilderFactory and on the other page, document is formed using DOMParser
Validate email id in jsp - JSP-Interview Questions
Validate email id in jsp  Hi Please Suggest me how to validate email id in JSP(Java Server Faces
Is JSF using JSP?
Is JSF using JSP?  Is JSF using JSP
MySQL Generate AlphaNumberic Id In JSP
numeric id using MySQL as database, tomcat 7 as a server for deploying the JSP...MySQL Generate AlphaNumberic Id In JSP In this section we will discus about how to generate id in specific format in MySQL and JSP. This example explains
getting dropdown values using apache commons in servlet
getting dropdown values using apache commons in servlet  i want... commoms,before that i was using o'reilly api. here is my code : @Override...); } i tried to debug and i am getting the wright file path but while proceeding
Upload Exce Data into MySql Using Jsp and Servlet - JSP-Servlet
Upload Exce Data into MySql Using Jsp and Servlet  now i am doing a project my concept is to insert the Excel File Data is uploaded and inserted.... My mail id [email protected]  Hi Friend, Please visit
getting and storing dropdown list in database in jsp
getting and storing dropdown list in database in jsp  i have a drop down list to select book from database. i'm able to retrieve dropdown list from... is inserted successfully"); %>   thanx for the quick response. i tried just
Jsp using mvc - JSP-Servlet
Jsp using mvc  hi I have written using mvc2 architecture, i have written logic in java ,i want to print a message on the form stating the the values are inserted successfully.So can you tell me how i have to write the code
tree using jsp code
tree using jsp code  i want to draw a tree structure of a family hierarchy using jsp code
Printing Session Id Using Variable
Printing Session Id Using Variable  Hi, I am a learner in PHP language. Could any one guide me, how to print session Id using variable in PHP. Thanks
how to create using jsp
how to create using jsp  code 1: <%@ page language="java..."/><br/> <input type="text" name="fname" id=""/><br/> <input type="text" name="lname" id=""/><br/> <input type
report generation using jsp
report generation using jsp  report generation coding using jsp
Getting File path error - JSP-Servlet
Getting File path error  I have a requirement where i need to get certain properties on application login page start itself. I an currently using String str = request.getRealPath("/")+"a" + System.getProperty( "file.separator
getting contacts from gmail - JSP-Servlet
getting contacts from gmail  hi there, would you please tell me step by step how can i integrate the gmail contacts with my web application. please reply me asap. I'll be greatfull to you. Rajesh
Creating, getting, and setting content using jQuery
Creating, getting, and setting content using jQuery       Creating, getting, and setting content using jQuery Using jQuery , you can add(create) html content
A Java Program by using JSP
A Java Program by using JSP  how to draw lines by using JSP plz show me the solution by using program

Ads