Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet Getting the last inserted id using jsp

Have Programming Question? Ask it here!
 
 
 


Godwin
Getting the last inserted id using jsp
1 Answer(s)      2 years and 8 months ago
Posted in : JSP-Servlet


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


Advertisement
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
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
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
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
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
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
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
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
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
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
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  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  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
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
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
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
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
How to get an Id vaue - JSP-Servlet
a respected cases.In that case i am calling a jsp by using a response.sendRedirect("./jsp/delete1.jsp"); then it sis going to that jsp where i need a id values and getting from strId = request.getParameter("Id"); But i am getting a null
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
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 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
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
Using Hibernate <generator> to generate id incrementally - Struts
Using Hibernate to generate id incrementally  Hi All, How to increment id using Hibernate ( or if any other) to generate id. I am using..... Mr.Sandeep. we do have many generator algorithms for our id, So you are incrementing id
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... and provides good performance for high traffic website. Getting Started with JSP You
How to get an Id vaue - JSP-Servlet
How to get an Id vaue  Dear Sir , How to get an Id value of a column when it is select ,i have to get an perticular rows Id value .I have a table with attributes like select,Id,subject,matter,status...If i select a one
Using Single Quote in Reciepient mail Id.
Using Single Quote in Reciepient mail Id.  Hi, Is it possible to send a mail to a Mail Account having singlequote (Ex: prasad'g@gmail.com) by using JAVA Mail API. Could you please give me the clarification.......   Hi
id
id  how to find date of birth and gender in id in html with the help of javascript
i need the source code to generate id in jsp
i need the source code to generate id in jsp  hai,i need the source code for generate id...which is i need to generate the new id from the maximum... of generate ids each should have some range...plz give the source code in jsp with ms
Validate Domain of an Email Id - JSP-Servlet
Validate Domain of an Email Id  How to validate the domain name in an Email id before sending a mail for an application using Mail API. ex: a@a.com in the above email id i want to validate whether a.com is present
[JSP] How to pass back ID to previous page.
[JSP] How to pass back ID to previous page.  Hi experts, May I ask... a UKM, it linked to ViewProducts.jsp <a href='lihatProduk.jsp?ID_UKM=" + rs.getString("ID_UKM") + "'title='Lihat Produk' class='icon-5 info-tooltip'<
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
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
Validating Emp ID Reply - JSP-Servlet
Validating Emp ID Reply  Respected Sir/Madam, I am Ragavendran.R.. Thanks for your quick response.. Actually I need to check whether Emp ID...("Employee ID cannot be null"); form.id.focus(); return false; } if(form.name.value
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
<%=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
Getting a Property value in jsp
Getting a Property value in jsp   ... a Property Value</H1> <jsp:useBean id="bean" class="form.GetProperties" />... GetProperties() {} } In the above example, we are using bean with <jsp
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
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
Difference between class,name,id attributes in each JSP tag
Difference between class,name,id attributes in each JSP tag  Can i know the difference between class,name,id attributes in each JSP tags.................. These 3 are only used for reference ..... And what are the differernces
Finding MAX value from emp_id column using SQL query?
Finding MAX value from emp_id column using SQL query?  I need to select maximum of the Emp_id values from SQL server 2005 table.I was using... of emp id from the table.(Actually it picks up Max value using by looking at 1st
Advertisements
 

 

 

DMCA.com