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.

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:
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
Advertisements
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
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
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
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
How to get data from DB in to Text box by using Jsp & Ajax
How to get data from DB in to Text box by using Jsp & Ajax   I want to get the data from database in to text box in a jsp page by using Ajax. If I... with a and from that i need to select the required value and i should store
Read code from excel sheet and upload into database using JSP
Read code from excel sheet and upload into database using JSP  I want to upload data to database from an excel worksheet using jsp ...Please help
tree using jsp code
tree using jsp code  i want to draw a tree structure of a family hierarchy using jsp code
data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp
data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp   data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp with script of data base plz help me
how to generate reports from oracle database using jsp and ajax code
how to generate reports from oracle database using jsp and ajax code  ... sales report data from oracle database to jsp page please any one know how to do this send me a code to my email:[email protected] its a humble request my team
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
how to insert array data into sql server using jsp
how 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 file
a 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-Servlet
html 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
using getText() to retrieve text from an array of text fields with loop.
using getText() to retrieve text from an array of text fields with loop.  ... presses button. Now I want to get the text from all the textfields using array...;i++) { value[i]=text[i].getText(); } //here value is an array. //text
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
How to get the text from textarea in HTML and store it in database using javascript and jsp
How to get the text from textarea in HTML and store it in database using javascript and jsp  How to get the text from textarea in HTML and store it in database using javascript and jsp <script> function str() { <
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 .   ...; ResultSet rs; res.setContentType("text/html"); PrintWriter out
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
how to retrieve text and images from mysql database and show on html page using jsp servlet
how to retrieve text and images from mysql database and show on html page using jsp servlet  <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> Insert title here h3
Data fetching from JSP or HTML - JSP-Servlet
Data 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 jdbc
HTML 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
online shopping code using jsp
online shopping code using jsp  plz send me the code of online shopping using jsp or jdbc or servlets plz plz help me
retrieve the data to text fields from database on clicking the value of combo box
retrieve the data to text fields from database on clicking the value of combo box   retrieve the data to text fields from database on clicking... getting data into textarea from database table by clicking on the button
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 Magazine
text 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
Importing data into sql plus from a text file...
Importing data into sql plus from a text file...  How to import a text file into oracle 10g enterprise edition directly to create tables and data
Importing data into sql plus from a text file...
Importing data into sql plus from a text file...  How to import a text file into oracle 10g enterprise edition directly to create tables and data
database connectivity using jsp code
database 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+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
HTML Login Page Code
HTML 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
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
to run html code in web browser - JSP-Servlet
to 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
Displaying the values in text fields of a form from a javascript function in jsp
Displaying the values in text fields of a form from a javascript function... to call a javascript function by passing 3 values from applet. And i have to display these values in 3 text fields of a form in the current web page. Here form
HTML code
HTML code  How do I keep people from stealing my source code and/or images
Sql Examples using php code
Here is the many examples. In this tutorial we discuss many examples of sql statements using php code
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
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session   sig
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session   sig   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 http://roseindia.net/jsp/bank.shtml
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
Javascript Code for all fields
Javascript 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 insert the value from jsp to access database
code for insert the value from jsp to access database  code for insert the value from jsp to access database
code for jsp to db connection using jdbc
code 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
code for selected checkbox columns data from database
code for selected checkbox columns data from database  in my page iam... one or more checkboxes i have to get data of that selected columns only. what is the jsp code for this thanks in advance kalyani
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 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... between your Tomcat server & Mysql database Table. Code to insert row in Mysql

Ads