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



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


puligundla deepak
retriving data from sql server using jsp code and placing them in text fields of html code
2 Answer(s)      3 years and 5 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?


Advertisement
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
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
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
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
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
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
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
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
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
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
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
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
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: siva.ssk83@gmail.com Regards, S
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
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
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
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() { <
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
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
tree using jsp code
tree using jsp code  i want to draw a tree structure of a family hierarchy using jsp 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
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:nemathdba@gmail.com its a humble request my team
insert and retrive image from sql server database in jsp
insert and retrive image from sql server database in jsp  what is the code to insert and retrive an image from sql server database in jsp
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
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
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
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
Advertisements
 

 

 

DMCA.com