Sanjeev
Web Related
1 Answer(s)      4 years and 3 months ago
Posted in : JSP-Servlet

View Answers

March 17, 2009 at 12:56 AM


Hi friend,

I am sending you few code as the JSP pages which will help you in solving your problem. In these JSP pages the first jsp page Updaterecord.jsp will allow you to see the updated records and as well as you can insert here the database records to be added. It internally calls the insertmid.jsp which after performing insertion will redirect to the Updaterecord.jsp page. Code is as follows :

Updaterecord.jsp

<%@ page language="java" import="java.io.*, java.sql.*" %>
<html>
<head>
<title>update record</title>
</head>
<body>
<table border="1">
<tr>
<td>Id</td>
<td>First Name</td>
<td>Last Name</td>
</tr>
<%
int id=0;
Connection con = null;
String url = "jdbc:mysql://192.168.10.211:3306/";;
String db = "amar";
String driver = "com.mysql.jdbc.Driver";
String userName ="amar";
String password="amar123";
String name="";
String lastName="";

try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,userName,password);

Statement st = con.createStatement();
String sqlQuery = "Select * from userinform";
ResultSet rs = st.executeQuery(sqlQuery);
while(rs.next())
{
%>
<tr>
<td><%=rs.getInt(1) %></td>
<td><%=rs.getString(2) %></td>
<td><%=rs.getString(3) %></td>
</tr>
<% }
}
catch(Exception e) {
System.out.println(e.getMessage());
}
%>

<center>
<table border="0" width="400px" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">
<center>
<h2><font color="#FF0033">Add data into database</font></h2></center>
<form name="updateForm" action="insertmid.jsp" method="GET" >
<input type="hidden" name="id" value="<%=id%>">
<table border="1" width="400px" cellspacing="0" cellpadding="0" bgcolor="#CCFFCC">
<td width="50%"><b>Name</b></td>
<td width="50%">
<input type="text" name="name" value="<%=name%>"></td></tr>
<td width="50%"><b>Last Name</b></td>
<td>
<input type="text" name="lsname" value="<%=lastName%>"><br/></td>
</tr>
<tr><td><center>
<input type="submit" name="update" value="Update"></center></td></tr>
</tr>
</table>
</form>
</td>
</tr>
</table>
</center>
</body>
</html>

// insertmid.jsp

<%@ page language="java" import="java.sql.*" %>

<%
Connection con = null;
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://192.168.10.211:3306/";;
String db = "amar";
String userName = "amar";
String password = "amar123";
if(request.getParameter("name")!=null && request.getParameter("lsname")!=null){
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,userName,password);
try{
Statement st = con.createStatement();
String name=request.getParameter("name");
String lsname=request.getParameter("lsname");
int val = st.executeUpdate("insert into userinform(name,lsname) values('"+name+"','"+lsname+"')");
con.close();
response.sendRedirect("Updaterecord.jsp");
}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
}
%>

Thanks for posting questions.
RoseIndia Team









Related Pages:
Web Related - JSP-Servlet
Web Related  Dear Sir, I am in truble, i need your help. How can i update my webpage by inserting the value in database. The webpage... time and all these values i want to show on my web page dynamically.plz help me
Internet and Web related questions for Web Master.
Internet and Web related questions for Web Master.   Explain the difference between the Internet and Web. What are Web browsers? Explain the two main functions of a Web browser. Write a note on the structure of a Web page. What
java related - Java Beginners
know where to start from. I have purchased one java related book. But I am... Microsystems. Though it is associated with the World Wide Web but it is older than the origin of Web. It was only developed keeping in mind the consumer electronics
Related to weblogic server8.1
Related to weblogic server8.1  hi Everybody, i have write a simple servlet program and deploy on weblogic8.1 server. when I'm running this app. when...:\firstApp\WEB-INF\classes;C:\bea\userprojects\domains\mydomain
jsp program related
inside the apache-tomcat>>webapps>>web application folder>> 6)You have to give appropriate name to web application folder like examples
XML Related Technologies: An overview
XML Related Technologies: An overview       Below is a list of XML-related technologies. DTD... (Web Services Description Language) is an XML-based language for describing web
web page
web page  1.Create a web page with the following using HTML i) To embed an image map in a web page ii) To fix the hot spots iii) Show all the related information when the hot spots are clicked
StringBuffer related.
StringBuffer related.  how to make StringBuffer as immutable
related to database
related to database  how to override existing values in table? when user enters his updated data through query
Related to Histogram
Related to Histogram  hi this is srinivasrao. In my project i have to display using chart for that i want to use histogram. k chart displayed but the values given by me is not related display chart so please give the code if u
Web 3
Web 3.0 Design Web 3.0 Design: REST, AJAX, Silverlight, Widget Enabled, Taggable, Searchable everything?  RSS. A Web 3.0 Driver In the coming ten years RSS and its related technologies will become the single most important
related to java
related to java  what is mean of }); in java.i know that } is used to close a block of statement,) is used to close a statement and ";"is used after close a statement but i can not usderstood the use of }); together in a java
Related to Project
Related to Project  how speech to text project can be make in java? Please tell me the coding part therapeutically i know i have to use java speech api which offer two technology 1. speech recognization 2. speech syenthesis
Session Related Interview Questions
Session Related Interview Questions   ... variable is associated with that session. In case of web applications the default... in the cookies, URLs (in case url rewriting) and hidden fields of Web pages. 
Web Development
of related web pages containing text, images, audio and videos and other digital... Web, consisting of an HTML file and any related files for scripts and graphics... Web Development Web development in general term is process
Web 3.0 Design
Web 3.0 Design       Web 3.0 Design: REST, AJAX, Silverlight, Widget Enabled, Taggable, Searchable everything?  RSS. A Web 3.0 Driver In the coming ten years RSS
Types of Web Hosting,Web Hosting types
the server for server failure and other related issues. Managed Web Hosting... Types of Web Hosting Here you will learn about the types of web hosting... valued websites. Your website plays an important role in your web business. So
Dumps related to weblogic certification
Dumps related to weblogic certification   I want to perform the weblogic certification exam code 1z0-110. Can anybody please provide me the dumps related to 1z0-110 Thanks in advance
Java and jvm related question
Java and jvm related question  What is difference between java data types and jvm data types
Overview of Web 3
Overview of Web 3.0 Overview  As the times goes and the technology..., advance, user friendly and intelligent. Thus originates the concept of web 3.0 and now it is taking a handsome shape. Web 3.0 have some more feature including
Question related to Hibernate
Question related to Hibernate  Why do we use Set in child class in 1:many hibernate ,why can't we use Directly HashSet
Server Related exception
Server Related exception  How will write code to handle serverside exceptions in our projects.Earlier we dont know which exception the code will throw
liferay related query
liferay related query  can you suggest me how to get all the session ids of different users logged in to liferay
Java Related Question
Java Related Question  hi, Why java doesn't has primitive type as an object,whats an eligibility to have a primitive type as an object by the languages
web
web  what do you mean by stacking elements? explain with example(in web programming
web
web  what do you mean by stacking elements? explain with example(in web programming
project related question
project related question  1- how to insert a date through hibernate 2- how to insert exact time ,date separetly in the data base for current time date
problem related to onSubmit() method
problem related to onSubmit() method  Hello, I am developing application.when i submit form at that time formBacking() method is call...Instead of that onSubmit() should have to call .... please help me
JDBC related query
JDBC related query  How to merge two resultset of two different queries, wherein both the resultset(after query execution)gives an integer value as its column
string related question
string related question  *q.1>how i dispaly the reference of string variableS ? eg:-String s1="my name"; Sring s2="your name"; here what is address of variable s1 and s2
iphone property list related
iphone property list related  question related to iphone application...... how to retrieve data from plist and again check the condition if data is found in plist then go to next view and print those value in table
Web Hosting Glossary
questions, comments and queries, answer the user queries related to the web hosting... Web Hosting RoseIndia.net's web hosting resource is top web hosting resource on the net. RoseIndia.net web hosting resource offers hundreds of excellent
query related to jdbc
query related to jdbc  hello, i have done my database connection successfully ie db2 with RAD. but while running my application i am not able to fetch the data so please suggest and help me
Struts related Question
Struts related Question  Hi All, I have a one question on validation framework for client side validation please help me on that. suppose i don't want to put required=true in our JSP then what will happen. what error will come
What is Web Graphics
descriptions on your web site, you should have the related graphic... What is Web Graphics Web graphics... of what they are looking for. Web graphics helps designers to enhance
java question related to objects
java question related to objects  what is the output of the following code? public class objComp { Public static void main(String args[]) { Int result = 0; objComp oc= new objComp(); object o = oc; if( o==oc) result =1; if(o
Window.open Method Related.
Window.open Method Related.  sir, i use to window.open method to popup window its works easily but when windows popped up at that time i want to disabled part, except popup window look like when alert(), prompt(). or other site
java related question
java related question  How can we make a program in which we make mcqs question file and then make its corresponding answer sheet....like if we make 15 mcqs then java should generate it answer sheet of 15 mcqs with a,b,c d
query related to uploading file
query related to uploading file  hello friends i am doing my project in servlet and i want to upload a file and store file in local hard drive and file name and path in oracle database.with name file name and path i also want
Everything about Web Writing
Everything about Web Writing       Writing for the Web The art of writing for the web....    Web Document Navigation Navigation of the web and of a web
related to multiple thread....!!!!
related to multiple thread....!!!!  Write a Java program, which creates a linklist for Employees info viz. EmpID, EmpName, EmpAge. All operations should be performed on the linklist, like; Create, Add, Delete, Update, Size
Jboss related linkage error
Jboss related linkage error  Please check below error when i run in jboss java.lang.LinkageError: loader constraint violation in interface itable initialization: when resolving method
Related to GenericServlet and HttpServlet
Related to GenericServlet and HttpServlet  Que: Http Servlet extends Generic Servlet then Why both GenericServlet and HttpServlet implements Serializable interface ?   GenericServlet and HttpServlet implement
Data base related question
Data base related question  sir my table has only one element(that is pno),i am using ms-access as backend. i put only one element i want to retrieve that element .how can i retrieve that element,using jdbc technology. please
query related to awt
query related to awt  Hi, I want to know how to check a text value is numeric or not when user enters the text to the textbox.After checking whether the enter text is numeric we need to display in LwDialog showing proper
scrollableDataTable Related issue
scrollableDataTable Related issue  Earlier Dynamic Data Table is created by using HtmlDataTable object and it is used in xhtml by using attribute binding. I have replaced HtmlDataTable object with HtmlScrollableDataTable object
JDBC ODBC related problem
JDBC ODBC related problem  i WANT HELP RELATED TO JDBC CONNECTIVITY WITH MS ACCESS.. HERE IS MY FULL CODE... import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import
web

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.