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



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Godwin
Getting the last inserted id using jsp
1 Answer(s)      3 years 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
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
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  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
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
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
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
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
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
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
Advertisements
 

 

 

DMCA.com