retriving data from sql server using jsp code and placing them in text fields of html code
Hi,
my question is how to retrieve data from sql server 2008 using a jsp file and place the values in the text fields of a html file.
i created a database table named
addclients
clientid 1000
name jhon
address abbanna clolony
my html page is
<table>
<form id="form7" name="form7" method="post" action="modify_clients.jsp">
<tr>
<td height="46"><div align="right">
<h3>Client ID</h3>
</div></td>
<td>
<label>
<input name="Client_id" type="text" id="textfield17" value="" />
</label>
</td>
</tr>
<tr>
<td width="120"><div align="right">Name</div></td>
<td width="288">
<label>
<input type="text" name="Name" id="textfield9" />
</label>
</td>
</tr>
<tr>
<td><div align="right">Address</div></td>
<td><input type="text" name="textfield9" id="textfield10" value="" /></td>
</tr>
<label>
<input type="submit" name="button3" id="button3" value="Modify" />
</label>
<label>
<input type="reset" name="button3" id="button4" value="Delete" />
</label>
</td>
</tr>
</form>
</table>
now i want to place the values of name "jhon" and address "abbanna colony" in those text fields using a query "select * from addclients where clinetid=1000".
the main theme of this page is when
anyone enter his clientid and click
modify button the details of the
person with clientid has to be
displayed on those text fields and
after changing his details and
pressing the submit button the values
have to be updated in the addclients
table.
can anyone plese send me the jsp code
to retrieve and set the data to the
html file?
View Answers
June 18, 2011 at 11:26 AM
1)ajax.jsp:
<%@page import="java.sql.*"%>
<html>
<head>
<script type="text/javascript">
function showData(){
xmlHttp=GetXmlHttpObject()
var id=document.getElementById("id").value;
var url="getdata.jsp";
url=url+"?id="+id;
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
var showdata = xmlHttp.responseText;
var strar = showdata.split(":");
if(strar.length>1)
{
var strname = strar[1];
document.getElementById("name").value= strar[1];
document.getElementById("address").value= strar[2];
}
}
}
function GetXmlHttpObject(){
var xmlHttp=null;
try{
xmlHttp=new XMLHttpRequest();
}
catch(e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>
</head>
<body>
<form method="post" action="update.jsp" >
<br><br>
<table >
<tr><td>Client ID:</td><td><input type="text" id="id" name="id" onkeyup="showData();"></td></tr>
<tr><td>Name:</td><td><input type="text" id="name" name="name"></td></tr>
<tr><td>Address:</td><td><input type="text" id="address" name="address"></td></tr>
<tr><td><input type="submit" value="Update"></td><td><input type="reset" value="Reset"></td></tr>
</table>
</body>
2)getdata.jsp:
<%@ page import="java.sql.*" %>
<%
int id = Integer.parseInt(request.getParameter("id"));
String data=" ";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from addclients where clientid ="+id+"");
while(rs.next())
{
data = ":" + rs.getString("name") + ": " + rs.getString("address");
}
out.println(data);
}
catch(Exception e){
System.out.println(e);
}
%>
</html>
3)update.jsp:
<%@page import="java.sql.*"%>
<%
String ide=request.getParameter("id");
int num=Integer.parseInt(ide);
String name=request.getParameter("name");
String address=request.getParameter("address");
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");
Statement st=null;
st=conn.createStatement();
st.executeUpdate("update addclients set name='"+name+"',address='"+address+"' where clientid ='"+num+"'");
out.println("Record is updated successfully!");
}
catch(Exception e){
System.out.println(e);
}
%>
October 10, 2012 at 2:55 PM
hi
i want to retrieve country name from mysql db to textfield..
maeans if anyone type first letter of the name it should show the corresponding names in the list.. like autocomplete.. ihave tried coding in this forum but its has some difficulties i caant able to select particular name to textfield...
it should be in jsp.. please help me out
Related Tutorials/Questions & Answers:
How to populate text fields using php code?How to populate
text fields using php
code? How could I use php to populate
text fields by selecting a name of a business
from dropdown list? Those
text fields that will be populated by information in regards its company name
Advertisements
populating text box using jsp codepopulating
text box
using jsp code Sir,
How to populate related values in a
text box after selecting value
from drop down list
using JSP and mysql.... Please give an example
using jsp code only.
dependentDropdown.jsp
tree using jsp codetree
using jsp code i want to draw a tree structure of a family hierarchy
using jsp code how to insert array data into sql server using jsphow to insert array
data into
sql server using jsp hello,
i have problem to insert array
data into my
sql server from jsp form. beloW is my
code...
from form, but not insert into my
sql database.
try {
//String
a jsp code for creating a text filea
jsp code for creating a
text file Hello,i need
jsp code for creating a new
text file for each user, when they login in to the website for creating a new
data file.
So i need a
jsp code for following options.
when user login
html dropdownlist code - JSP-Servlethtml dropdownlist code hi
how to get textfield in
html when i select the option others in the dropdown list, pls provide the
code?
Hi Friend,
Try the following
code:
function show(){
var op
Html/JavaScript code - JSP-ServletHtml/JavaScript code I have 2 JSPs JSP1 and JSP2.
1.in JSP1 i have a table being displayed
using the tag and cells in it contain links(huge amount of
data is displayed in paged manner).
2.When click on a link, it leads
How to hide HTML code from user? - SecurityHow to hide
HTML code from user? Hi All,
I am trying to provide..., or dynamically
from the
server using ajax. There is no way to eliminate reconstruction... viewing
HTML source
code.
Can any one guide me for this topic?
Thanks
Data fetching from JSP or HTML - JSP-ServletData fetching
from JSP or HTML Hi Deepak,
Can u pls help me as i have a problem with
jsp/
html frameset.
my question is how can i fetch the
data from frameset which is in
html format.pls help me.
Thanks
HTML code to servlet to database using jdbcHTML code to servlet to database
using jdbc pls send me the
code related to the title
Hi Friend,
Try the following
code:ADS... {
String msg=req.getParameter("msg");
res.setContentType("
text/
html View source code of a html page using java ..View source
code of a
html page
using java .. I could find the
html source
code of a web page
using the following program,
http://download.oracle.com/javase/1.4.2/docs/api/java/net/URLConnection.html
i could get the
html code text to speech code in jsp - Java Magazinetext to speech
code in jsp Is their any
code in
jsp for
text to speech
i.e when i enter
text in
text area and press submit button , the
text i entered should come in voice as output
database connectivity using jsp codedatabase connectivity
using jsp code i have two tables employee...)values('6867678po',(select Ename
from employee),(select Designation
from employee),'bbbb','bbbb'); so this syntax is possible to use in
jsp code
based
how to insert data in database using html+jsphow to insert
data in database
using html+jsp anyone know what... = null;
// declare a resultset that uses as a table for output
data from... = 0;
//
sql query to retrieve values
from the specified
HTML Login Page CodeHTML Login Page
Code
Here is an example of
html login page
code... for submitting
data to
server for validation. Its
good to validate user input in the browser
using JavaScript. In this tutorial we
are creating a
HTML Login
to run html code in web browser - JSP-Servletto run
html code in web browser how to run
jsp file which calls
html file on web browser?? Hi Friend,
Try the following
code:
1)form.jsp:
Enter Name:
2)welcome.html:
Add Profile
Edit
how to insert, retrieve data from,to db(code)....how to insert, retrieve
data from,to db(
code).... Hi.....
i ve... that
data will b stored in db(m
using sybase).
2.also hw to retrieve the
data from...)
if it is in login pgm whr it shud b coded(before username,pasword
fields code r after
HTML codeHTML code How do I keep people
from stealing my source
code and/or images
how to insert, retrieve data from,to db(code)....how to insert, retrieve
data from,to db(
code).... Hi, i have created... will b stored in db(m
using sybase).
2.also hw to retrieve the
data from db. cn u... coded(before username,pasword
fields code r after that..... 4.n still wt r d
Retrieve data from databse using where in JSPRetrieve
data from databse
using where in JSP Hi, can somebody help me?
I have a
jsp page. in that i want to get
data from the database where...=request.getParameter("username");
String
sql;
sql="SELECT *
FROM register WHERE
Javascript Code for all fieldsJavascript
Code for all fields Good Evening Sir/Madam,
Please send me the example program
using bootstrap framework for all
fields of a form. Please send me the javascript
code
My E-mail id:
[email protected]
Regards,
S
code for jsp to db connection using jdbccode for
jsp to db connection
using jdbc please send me the
code
Hi Friend,
Try the following
code:ADS_TO_REPLACE_1
1)form.html:
<html>
<form method="post" action="http://localhost:8080/examples/
jsp jsp programe for displaying data from database/WebSevices/19592-retriving-
data-
from-
sql-
server-
using-
jsp-
code-and-
placing-
them-in-
text-
fields-of-
html-code.html
http://www.roseindia.net/answers/viewqa/
JSP...
jsp programe for displaying
data from database i am
using JSP.i want
jsp programe for displaying data from database/WebSevices/19592-retriving-
data-
from-
sql-
server-
using-
jsp-
code-and-
placing-
them-in-
text-
fields-of-
html-code.html
http://www.roseindia.net/answers/viewqa/
JSP...
jsp programe for displaying
data from database i am
using JSP.i want
jsp programe for displaying data from database/WebSevices/19592-retriving-
data-
from-
sql-
server-
using-
jsp-
code-and-
placing-
them-in-
text-
fields-of-
html-code.html
http://www.roseindia.net/answers/viewqa/
JSP...
jsp programe for displaying
data from database i am
using JSP.i want
Insert a row in 'Mysql' table using JSP CodeInsert a row in 'Mysql' table
using JSP Code
In this section, we will discuss about how to insert
data in Mysql database
using JSP code.
Query...
between your Tomcat
server & Mysql database Table.
Code to insert row in Mysql