retrieving data from database to the textbox depending upon the id in jsp
Hi,
our project involves fetching of data from database into textbox depending upon another textbox value which is productid.First the id entered by us will be checked to database weather it exist or not and if it exists the corresponding producttype and product_price should populate into textbox,which a user cannot modify.
Please provide the respective code..Waiting for your reply.
View Answers
July 4, 2011 at 11:29 AM
1)checkid.jsp:
<%@page import="java.sql.*"%>
<html>
<head>
<script type="text/javascript">
function showData(){
xmlHttp=GetXmlHttpObject()
var id=document.getElementById("id").value;
var url="id.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("type").value= strar[1];
document.getElementById("price").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>
<br><br>
<table >
<tr><td>ID:</td><td><input type="text" id="id" name="id" onkeyup="showData();"></td></tr>
<tr><td>Product Type:</td><td><input type="text" id="type" name="name"></td></tr>
<tr><td>Price:</td><td><input type="text" id="price" name="address"></td></tr>
</table>
</body>
</html>
2)id.jsp:
<%@ page import="java.sql.*" %>
<%
String id = request.getParameter("id").toString();
System.out.println(id);
String data ="";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from item where itemid='"+id+"'");
while(rs.next())
{
data = ":" + rs.getString("item") + ": " + rs.getString("price");
}
out.println(data);
System.out.println(data);
}
catch(Exception e) {
System.out.println(e);
}
%>
July 21, 2011 at 12:17 PM
hi,
great job.
I have the same problem.plz help me.
I have MySQL DataBase/DB Name:lokesh;
Table Name:TR_list;
columns:nodename,packageno,TR;
Values(crs,cs 4.0,xxx),
Values(sdp,cs 5.0,yyy),
Values(air,cs 6.0,zzz),
i want to create a viewTR.jsp file in netbeans IDE,
where i have to :
1.connect to DB in MYSQL and
2.TR List:input Text Box and button.
3.In the same viewTR.jsp file, i have to display the Nodename and packageno.
i.e.,select nodename,packageno from TR_list where TR='xxx';
Plz help me
Ads
Related Tutorials/Questions & Answers:
Advertisements
How to show data from database in textbox in jsp
How to show
data from database in
textbox in
jsp How to show
data from database in
textbox in
jsp
Here is an example that retrieve the particular record
from the
database and display it in
textbox using
JSP.
<
Getting Textbox data from database
Getting
Textbox data from database When i m trying to get
data in
textbox as readonly
from database i m getting following error.and my code is shown...
data from database and display it on the textboxes.
<%@page language="java
Getting Textbox data from database
;Here is a
jsp code that retrieves
data from database and display...Getting
Textbox data from database When i m trying to get
data in
textbox as readonly
from database i m getting following error.and my code is shown
Retrieving Data from Database to fill Combo Box
Retrieving Data from Database to fill Combo Box Sir,
I have a
JSP Page with a combo box and a label. I have a
database that has two fields
id... displaying path that is stored in the
database but not the image itself. Kindly
Retrieving data from data base using jsp combo box
Retrieving data from data base using
jsp combo box Hi guys please help me , i have on GUI page int that Server type(like apache,jboss,weblogic) one... of the server it has to display the process name
from database into the process name
retrieving from oracle database using jsp combo box
retrieving from oracle
database using
jsp combo box hi this is my... name of the server has to display in the process name field
from the oracle
database please help on this i need code using servlets please help me .
<
retrieving from db - JSP-Servlet
; Hi
Retrive value
from database
Retrive
data from database
User
id:
Course Name
Courese Fee...
retrieving from db hello'
I am trying to write my first application
retrieving xml document from database
retrieving xml document
from database Hi Guys,
I want to retrieve the xml document stored in the
database on to a
jsp page using jdbc/odbc connnection.Please help me in implementing this feature.
Thank You
Madhu
how to check dates while retrieving data from database
how to check dates while
retrieving data from database i want to update
database record based on delivery date i have tried this query but it wont work
b="update deliveryorder set prtnm='"+arr[1]+"',stn='"+arr[0]+"',sbston
retrieve related data from database using jsp and mysql
retrieve related
data from database using
jsp and mysql Hi sir,
please give some example of
jsp code for
retrieving mysql
database values in multiple dropdown list. if we change a value in a dropdown its related value must
Dynamically Update textbox from database
Dynamically Update
textbox from database I have a
database as shown below.(
database created using SQL Server 2005)
name : george,simon
address... to that typed value
from database has to be displayed in another text box
How to Retrieve data from database in jsp
How to Retrieve
data from database in
jsp
In this section we will discuss... tableName" for
retrieving the
data from database table and execute this query... is the video tutorial of "How to retrieve
data from database and Display in
JSP Page
data retrival from database throw simple jsp..
data retrival
from database throw simple
jsp.. We can retrieve the the
data from data base simple
jsp page:
Jsp Page:retrive.jsp
<...;
Statement stmt = null;
String Query="SELECT *
FROM STUD";
try
Display Data from Database in JSP
, to show
data from the
database
click on the link that calls another .
jsp file named...;body>
<h2>
Data from the table 'stu_info' of
database 'student'</h2... this
jsp page and show all
data from the table.
Click on the <--back