How to display data fom MySQL DataBase-table in to JSP file by submitting a value in combobox.
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
View Answers
July 21, 2011 at 1:16 PM
1)select.jsp:
<%@page import="java.sql.*"%>
<html>
<head>
<script type="text/javascript">
function showEmp(id){
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
alert ("Browser does not support HTTP Request")
return
}
var url="getvalue.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];
document.getElementById("email").value= strar[3];
}
}
}
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 border="0" width="400px" align="center" bgcolor="#CDFFFF">
<div id="mydiv"></div>
<tr><td><b>Select Employee Name</b></td><td>
<select name="id" onchange="showEmp(this.value);">
<option value="-1">Select</option>
<%
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 id from employee");
while(rs.next()){
%>
<option value="<%=rs.getString("id")%>"><%=rs.getString("id")%></option>
<%
}
%>
</select>
</td></tr>
<tr><td ><b> Name:</b></td><td>
<input type="text" name="name" id="name" value=""></td></tr>
<tr><td ><b> Address:</b></td><td>
<input type="text" name="address" id="address" value=""></td></tr>
<tr><td><b> Email:</b></td><td>
<input type="text" name="email" id="email" value=""></td></tr>
</table>
</form>
<table border="0" width="100%" align="center">
<br>
<br>
</table>
</body>
</html>
2)getvalue.jsp:
<%@page import="java.sql.*"%>
<%
try{
String emp_id = request.getParameter("id").toString();
String data="";
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st=con.createStatement();
String query = "select * from employee where id='"+emp_id+"'";
ResultSet rs = st.executeQuery(query);
while(rs.next())
{
data = ":" +rs.getString("name") +":"+ rs.getString("address") +":"+ rs.getString("email");
}
out.println(data);
System.out.println(data);
}
catch (Exception e) {
e.printStackTrace();
}
%>
The above code will help you in solving your problem
Related Tutorials/Questions & Answers:
Advertisements
how to display data from jsp file into databasehow to
display data from
jsp file into database this is a
jsp file...+",'"+email+"')");
out.println("
Data is successfully inserted into
database...");
con = (Connection)DriverManager.getConnection("jdbc:
mysql://localhost
php csv file uploding into mysql database table.php csv
file uploding into
mysql database table. hai friends,
i... fields.
i have one
mysql database table with two files fields,
when ever i am uploding csv
file, i want to fetch the datas in corresponding fields in
table.
can
how to create database and table using jsphow to create
database and
table using jsp hi frnds....,
i want to create
database and
table in
mysql using
jsp.... i have an registration form(name,sex,address,phone and so on ... ) i want to create individual
table in
mysql Display Blob(Image) from Mysql table using JSP Display Blob(Image) from
Mysql table using
JSP
In this section, we will
display blob
data(image) from
Mysql database table
using
JSP code.
A Blob stores... Also :
Insert Blob(Image) in
Mysql table using
JSP
Download Source CodeADS
How to display the data column on jspHow to
display the
data column on jsp My requirements:
Display total...
..
in
table of each
database having two columns: description, error. but
data...;
</form>
It
display the
data of last
database server
How to Display jrxml file on JSP page???How to
Display jrxml
file on
JSP page??? I made jrxml
file using jasper report but
how to
display on
jsp page??
i tried lot but still i didnt find out solution.so pls help me as soon as possible
how to select second combobox value .how to select second
combobox value . I requirement is ,
i have two combo box, i am selected first combo box
value then automatically second combo box
value show ,But this both combo box
value i retrieves in
database.
please
Display Mysql "Blob" data using servletDisplay Mysql "Blob"
data using servlet
In this section, we will discuss about
how to
display a blob
data stored in
database table. A Blob stores a binary large object in the
database table's row.
Blob object
how to display the excel file content in the jsphow to
display the excel
file content in the jsp
How to present the content of the newly created excel
file in the following
jsp to the web browser:
print("code sample");
<%@ page import="java.io.InputStream" %>
How to Retrieve data from database in jspHow to Retrieve
data from
database in
jsp
In this section we will discuss about
how to fetch
data from
database table.
We will give a simple example which will demonstrate you about fetching
data
from
database table.
Example
We
MySQL Generate AlphaNumberic Id In JSP the record from
database table in
JSP and
display the record
in specific format...
how to generate id in specific format in
MySQL and
JSP.
This example explains... numeric id using
MySQL as
database, tomcat 7 as a server
for deploying the
JSP How to display data in jsp from dao using java beans?How to
display data in
jsp from dao using java beans? Hi
I need to
display data in
jsp pulling from dao using java beans, Please can anyone give me the sample application with above topics. Any help would be highly appreciated
Insert Blob(Image) in Mysql table using JSPInsert Blob(Image) in
Mysql table using
JSP
In this Section, we will insert blob
data(image) in
Mysql database table
using
JSP code.
A Blob stores a binary..._TO_REPLACE_8
See also :
Display Blob(Image) in
Mysql table using
Insert text into database table using JSP & jQueryInsert text into
database table using
JSP & jQuery
In this tutorial , the text is inserted into
database table using
JSP &
jQuery. In the below example, the first
JSP page is use to
display text box in
which we type
data jsp page submittingjsp page submitting whenever i am
submitting the
jsp page it downloads some unknown
file on tomcat server
Inserting values in MySQL database table insert values in
the
MySQL database table. We know that tables store
data in rows... Inserting values in
MySQL database table
... the facility
for inserting the values in
MySQL database table.
Description
how to store data in XML file - JSP-Servlethow to store
data in XML file hi
i have to store the
data for example user id and password in a xml
file the input userid and password will be coming from
jsp middle ware servlet
how to do that? Hi friend