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



Home Answers Viewqa JavaScriptQuestions How to "Get data froom MySQL DB on giving a value in a tex-box in a JSP file."
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


lokeshreddy
How to "Get data froom MySQL DB on giving a value in a tex-box in a JSP file."
1 Answer(s)      3 years and 2 months ago
Posted in : JavaScript Questions


Hi, How to get data from MYSQL Database tables on giving a "text" in a text-box in a JSP file. Ex:dept table; if we give dept_no in a text-box in JSP file,we have to retrieve the other fields from the dept table and display it in the same JSP file.

Help me plz;


Advertisement
View Answers

July 22, 2011 at 11:05 AM


1)ajax.jsp:

<%@page import="java.sql.*"%>
<html>
<head>
<script type="text/javascript">
function showData(id){ 
xmlHttp=GetXmlHttpObject()
    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").style.visibility= "visible";
        document.getElementById("address").style.visibility= "visible";
        document.getElementById("contactNo").style.visibility= "visible";
        document.getElementById("email").style.visibility= "visible";

        document.getElementById("lab1").style.visibility= "visible";
        document.getElementById("lab2").style.visibility= "visible";
        document.getElementById("lab3").style.visibility= "visible";
        document.getElementById("lab4").style.visibility= "visible";

        document.getElementById("name").value= strar[1];
        document.getElementById("address").value= strar[2];
        document.getElementById("contactNo").value= strar[3];
        document.getElementById("email").value= strar[4];
        }
       } 
     } 
    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 name="employee" >
<br><br>
<table >
<div id="mydiv"></div>
<tr><td>Enter Id:</td><td><input type="text" id="id" onkeyup="showData(this.value);"></td></tr>
<tr><td><label id="lab1" style="visibility:hidden">Name:</label></td><td><input type="text" id="name" style="visibility:hidden"></td></tr>
<tr><td><label id="lab2" style="visibility:hidden">Address:</label></td><td><input type="text" id="address" style="visibility:hidden"></td></tr>
<tr><td><label id="lab3" style="visibility:hidden">Contact No:</label></td><td><input type="text" id="contactNo" style="visibility:hidden"></td></tr>
<tr><td><label id="lab4" style="visibility:hidden">Email:</label></td><td><input type="text" id="email" style="visibility:hidden"></td></tr>
</table>
</body>
</html>

2)getdata.jsp:

<%@ page import="java.sql.*" %> 
<%
String emp_id = request.getParameter("id").toString();
 String buffer="";  
 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 employee where id='"+emp_id+"'");  
   while(rs.next()){
   buffer=":" +rs.getString("name") +":"+ rs.getString("address") +":"+rs.getString("contactNo")+":"+  rs.getString("email");
   }
 out.println(buffer);
 System.out.println(buffer);
 }
 catch(Exception e){
 System.out.println(e);
 }
 %>


Related Tutorials/Questions & Answers:
How to "Get data froom MySQL DB on giving a value in a tex-box in a JSP file."
How to "Get data froom MySQL DB on giving a value in a tex-box in a JSP file."  Hi, How to get data from MYSQL Database tables on giving a "text" in a text-box in a JSP file. Ex:dept table; if we give dept_no in a text-box in JSP
how to code
how to code  how to create mysql coding in php
Advertisements
how to update
how to update   conditional update
how to display?
how to display?  How to write a select query for displaying data where i have author as multivalued attribute
how to display?
how to display?  How to write a select query for displaying data where i have author as multivalued attribute
how to display?
how to display?  How to write a select query for displaying data where i have author as multivalued attribute
How to connect
How to connect  how to connect to a remote host using jsp? We need to update files to the database of the application on the local machine from the updated database on our webpage
How to include?
How to include?  How can we include a JSP file in one application to the JSP file in another application which are in the same server?? please help me out with code
how to solve
how to solve   log4j:WARN No appenders could be found for logger (org.apache.struts.util.PropertyMessageResources). log4j:WARN Please initialize the log4j system properly
How to add
How to add   Hi, I want to make a website which will recommend users books according to the genre selected by them. I am using PHP, JavaScript and mySQL. The problem is that there will me almost more than 100 books
how to do this?
how to do this?   Given any integer 2D array, design then implement a Java program that will add to each element in the array the corresponding column number and the corresponding row number. Then, it prints the array before
how to solve this..
how to solve this..  Given a list of students and their marks Name... dimensional arrays for the marks. From this creation get : a. Convert marks... in that class. d. List of student that get 100 in each subject
how to solve this..
how to solve this..  Given a list of students and their marks Name... dimensional arrays for the marks. From this creation get : a. Convert marks... in that class. d. List of student that get 100 in each subject
How to? - IoC
How to?  I am having problems coding my LOC to count constructors and methods?  Hi , Methods and constructors both use super to refer to a superclass, but in different ways. Methods use super to execute
how to retrive
how to retrive  this my servlet page.. @Override protected void... (Exception e) { System.out.println("......."+e); } } and this is my jsp..." value="Edit" style="background-color:#49743D
how to display?
how to display?  I have to write a code for searcing books in library...:8080/examples/jsp/searchbook.jsp" method="post"> <table align="center"> <...; </tr> <tr> <td> <input type="submit" value="Search" />
VoIP HOW TO
to the telephone companies box is in order.     How does VoIP... How to work It is very easy to get into a discussion that is very technical... VoIP HOW TO How to Distribute VoIP We recommend using
how to reset JFrame
how to reset JFrame  how to reset JFrame
How to: generic array creation
How to: generic array creation  How to: generic array creation
How to put an image on a JButton?
How to put an image on a JButton?  How to put an image on a JButton
How to use Servlet and Ajax?
How to use Servlet and Ajax?  How to use Servlet and Ajax
How to add JTable in JPanel
How to add JTable in JPanel  How to add JTable in JPanel
how to add to numbers in java
how to add to numbers in java  how to add to numbers in java
how to run rmi program
how to run rmi program  how to run rmi program
how to create notepad in java
how to create notepad in java  how to create notepad in java
How to Become a Business Analyst
How to Become a Business Analyst  How to Become a Business Analyst
how to send message
how to send message  how to send message for mobile in server
how to connect webcam in html
how to connect webcam in html  how to connect webcam in html.emphasized text
how to download oracle 9i
how to download oracle 9i  how to download oracle 9i
how to set class path
how to set class path  how to set class path in java
how to load pdf on html
how to load pdf on html  how to load pdf on html
 

 

 

DMCA.com