Home Answers Viewqa WebSevices retriving data from sql server using jsp code and placing them in text fields of html code

 
 


puligundla deepak
retriving data from sql server using jsp code and placing them in text fields of html code
2 Answer(s)      a year and 11 months ago
Posted in : WebSevices

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 Pages:
retriving data from sql server using jsp code and placing them in text fields of html code
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
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
Retriving data stored in database
Retriving data stored in database  Hi, How to retrive data from my sql database using Hibernate,Spring and tapestry please give me an example.I am new to this Hibernate and Spring
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
Placing components on each other - Java Tutorials
on it. One way is to use HTML text, but then the default font is different...Placing components on each other 2002-02-15 The Java Specialists' Newsletter [Issue 041] - Placing components on each other Author: Dr. Heinz M. Kabutz
how to insert data in database using html+jsp
how 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
JSP code
JSP code  I get an error when i execute the following code : <%@ page language="java" contentType="text/html; charset=ISO-8859-1...; <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
Access all the fields from table through JSP
the data from table when clicked. This is the code of first welcome jsp page. ... Access all the fields from table through JSP... data from the specified table. Before running this java code you need
how to display data from mysql table in text box using jsp??
how to display data from mysql table in text box using jsp??  <p>hi, i have a written a code to display data from a mysql table into txtboxes...; <pre class="prettyprint"> // sql query to retrieve values from
place data in text fields from database using jdbc
place data in text fields from database using jdbc  i want get the data from database and place the records in the respective textfields using jdbc and swing like eno,ename,loc from emp table
code
="JavaScript"> function MyClass() { var m_data = 15; var m_text = "indian... ) { m_data = myVal; } function SetText( myText ) { m_text = myText... this(in bold) because when i remove them and try calling the functions via object
How to hide HTML code from user? - Security
How 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
validating text fields - Swing AWT
validating text fields  hi i am using NETBEANS IDE so when i want...() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code
Retrive data from databse to a text field - Java Server Faces Questions
Retrive data from databse to a text field  Hi, Can you give me a source code to rertrve data from Mysql databse to a text field using JSF.....by selecting option from a dropdown option
ajax and jsp code - Ajax
ajax and jsp code  can u please give me the code for retriving the data from database using ajax our requriment is if i select country name in listbox display the corresponding all the states. using jsp and ajax   
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
populating text box using jsp code
populating 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
HTML
this field in form the data will be store into database.my database is the sql server... it shows as null. here is the html code for date of birth: <tr> <... addOption(selectbox,text,value ) { var optn = document.createElement("OPTION
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
jsp code for display of data from database and snap shot of the output
jsp code for display of data from database and snap shot of the output  i am using JSP.i want to insert data into database and also want to display the things i have entered in the same page inside the corresponding fields
JSP Get Data Into Dropdown list From Database
data from the database and set it into the dropdown list in JSP using MySQL...JSP Get Data Into Dropdown list From Database In this section we will discuss... fetching of data into the dropdown list in JSP using Eclipse IDE and the Tomcat 7
fetching data using servlets - SQL
fetching data using servlets  I have successfully made connection with the oracle10g database that i am using and also able to put in data using JSP... for fetching data from a ORACLE10g database using SERVLETS.   Hi Friend
date problem in sql server - SQL
is sql server 2000.i am getting the date problem when using in jsp page.  Hi Friend, Try the following code: retrieveDate.jsp: ID Work...date problem in sql server  select count(*) from xxxx_tbl where
dropdown list and text fields in php
dropdown list and text fields in php  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, suite
Html/JavaScript code - JSP-Servlet
Html/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
reading data from a text box with the same name using servlets - JSP-Servlet
reading data from a text box with the same name using servlets  ... like a= b= c= using servlet i want to print all the values from each text...,HttpServletResponse res)throws ServletException,IOException{ res.setContentType("text/html
jsp code - JSP-Servlet
jsp code  i want to add below code data in mysql database using jsp... using below code we got data in text box i want to add multiple data in database... Add/Remove dynamic rows in HTML table
data retrivel code - XML
data retrivel code  Can someone help me in retriving data from MySql database into an XML file using java.  Hi Shruti, Please visit the following link given for solving your problem. http://www.roseindia.net
Retriving data from MYSQL without line break using java
Retriving data from MYSQL without line break using java  get data without line breaking from mysql table (i.e data stored as mediumtext )using java
how to save html form data into .csv file using only jsp.
how to save html form data into .csv file using only jsp.  Dear all, I am developing a website only using jsp and html. i need to save the form data into a .csv file using jsp. can anyone give me any sample solution or tutorial
jsp code - JSP-Servlet
the second drop down list is displayed from mysql data base table by using select... to generate second drop down list by using jsp? pls ?   Hi Friend...").options[cid].text; window.location.replace("http://localhost:8080/examples/jsp
JSP Get Data From Database
JSP Get Data From Database In this section we will discuss about how to get data from database using JSP. To get data from database to a JSP page we... example which lets you understand to fetch data from database in JSP
Java servlet with jsp on sql server
Java servlet with jsp on sql server  How to delete a user by an admin with check box in Java Servlet with jsp on Sql Server?   Here is a jsp example that can delete the multiple record from the database by selecting
create a xml from sql server 2005 - XML
create a xml from sql server 2005  hello Dear, i want to know how we create a xml file which retrieve data from Sql server 2005 using java. i am briefing my problem as follows. let i have a table in sql server 2005
Inserting data from the HTML page to the database
Inserting data from the HTML page to the database... in the Html form will be retrieved by the server side program which we are going... the html will be set in the database by using the setString() method
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans   ... for retrieving data fromm two tables : first table having fields: bookid,name...).second .java file for getting data from second table- package pack; public
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans   ... for retrieving data fromm two tables : first table having fields: bookid,name...).second .java file for getting data from second table- package pack; public
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans   ... for retrieving data fromm two tables : first table having fields: bookid,name...).second .java file for getting data from second table- package pack; public
retriving image from database - JSP-Servlet
retriving image from database  how to retrive image from mysql database by using servlet programming  Hi Friend, Please visit the following link: http://www.roseindia.net/servlets/retreiveimage.shtml Thanks
Ajax Code Libraries and Tools
method calls on server directly from HTML page using JavaScript and return backs... of data requests from a Java application server to a web browser HTML form without... XML data into their HTML documents using HTML, CSS, and a minimal amount
Insert a row in 'Mysql' table using JSP Code
Insert 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... connector.jar file from-- http://www.oracle.com/technology/products/database
javascript code problem - JSP-Servlet
; "> in above code which is jsp and struts form bean... fields filled with values).now i will select a particular value from list box... to the variable.using that variable we can extract the data in database using string
Sending form data from HTML page to SQLserver 2005 database by calling servlet code
Sending form data from HTML page to SQLserver 2005 database by calling servlet... from html page to database by calling servlet code from html page .   ...; res.setContentType("text/html"); PrintWriter out = res.getWriter
Display Data from Database in JSP
, to show data from the database click on the link that calls another .jsp file named...;title>display data from the table using jsp</title> </head> <... this jsp page and show all data from the table. Click on the <--back
Retrieve data from databse using where in JSP
Retrieve 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
data are not display in JSP from database - JSP-Servlet
data are not display in JSP from database   i want to finding some data through a SQL query from SQL server database to a JSP page based on some... of this jsp page. like.. School Result and three request parameters 'class', 'from
jsp code error - JSP-Servlet
jsp code error  I have a jsp page named "tMastDepartment".which has some table row containing text box like 'project code','Departmentcode','employee... dropdown list then all the related data get populated from the database in textbox.then
HTML code to servlet to database using jdbc
HTML code to servlet to database using jdbc  pls send me the code related to the title   Hi Friend, Try the following code: 1)form.html...=req.getParameter("msg"); res.setContentType("text/html"); PrintWriter

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.