How to retrieve data from database by using combo box value in jsp?

Ads
 

How to retrieve data from database by using combo box value in jsp?

Hello friend i want use only one jsp page.. but u give 2 pages...
I want to work in one page...
Pl response.. I do not need getParameter...

Pl respose me.

Your code here..

CREATE TABLE "user"
(
"name" character varying(100),
eid character varying
)

--------code ------------------------------getuser.jsp----------------------------------
<%@ page import="java.sql.*" %>
<%
String emp_id = request.getParameter("emp_id").toString();
String data ="";

Connection conn = null;
String url = "jdbc:edb://127.0.0.1:5444/";;
String dbName = "nb";
String driver = "com.edb.Driver";
String userName = "enterprisedb";
String password = "OLIMPUS";

int sumcount=0;
Statement st;
try {
Class.forName(driver).newInstance();

conn = DriverManager.getConnection(url+dbName,userName,password);
String query = "select name,eid from public.user where name='"+emp_id+"'" ;

st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next())
{
data = ":" + rs.getString(1)+" " + rs.getString(2) ;
}


out.println(data);
}
catch (Exception e) {
e.printStackTrace();
}
%>

---------------------------combobox.jsp------------------------------------
------------
<%@ page import="java.sql.*" %>
<html>
<head>
<style>
A:hover {text-decoration: none;

border: 0px;
font-size:14pt;
color: #2d2b2b; }
</style>

<link rel="stylesheet" type="text/css" href="datepicker.css"/>


<script type="text/javascript">
function showEmp(emp_value)
{
if(document.getElementById("emp_id").value!="-1")
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="getuser.jsp"
url=url+"?emp_id="+emp_value

xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)

}
else
{
alert("Please Select Employee Id");
}
}

function stateChanged()
{
document.getElementById("ename").value ="";
document.getElementById("emp_id").value ="";
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{

var showdata = xmlHttp.responseText;
var strar = showdata.split(":");

if(strar.length==1)
{
document.getElementById("emp_id").focus();
alert("Please Select Employee Id");
document.getElementById("ename").value =" ";
document.getElementById("emp_id").value =" ";

}
else if(strar.length>1)
{
var strname = strar[1];
document.getElementById("emp_id").value= strar[2];
document.getElementById("ename").value= strar[1];
}

}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
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 Id</b></td><td>
<select name="semp_id" onchange="showEmp(this.value);">
<option value="-1">Select</option>
<%



Connection conn = null;
String url = "jdbc:edb://127.0.0.1:5444/";;
String dbName = "nb";
String driver = "com.edb.Driver";
String userName = "enterprisedb";
String password = "OLIMPUS";

int sumcount=0;
Statement st;
try {
Class.forName(driver).newInstance();

conn = DriverManager.getConnection(url+dbName,userName,password);
String query = "select name from public.user";

st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
%>

<%
while(rs.next())
{
%>

<option value="<%=rs.getString(1)%>"><%=rs.getString(1)%></option>

<%
}
%>

<%

}
catch (Exception e) {
e.printStackTrace();
}

%>

</select>
</td></tr>


<tr><td ><b>Employee Id:</b></td><td><input type="text" name="emp_id" id="emp_id" value=""></td></tr>
<tr><td><b>Employee Name:</b></td><td><input type="text" name="emp_name" id="ename" value=""></td></tr>

</table>
</form>

<table border="0" width="100%" align="center">


<br>
<br>


</table>
</body>
</html>
View Answers

Ads









Related Tutorials/Questions & Answers:
How to retrieve data from database by using combo box value in jsp? - JSP-Servlet
How to retrieve data by using combo box value in jsp? - JSP-Servlet
Advertisements
retrieve the data to text fields from database on clicking the value of combo box
How to retrieve data by using combo box value in jsp? - JSP-Servlet
How to retrieve data using combo box value in jsp? - JSP-Servlet
How to retrieve data by using combo box value in jsp? - JSP-Servlet
Populate a combo box using data from a database
how to retrieve data from database using combobox value without using request.getParameter in jsp - JSP-Servlet
Acees data from database using combo box - JSP-Servlet
how i conditional access the data from database using combo box. - JSP-Servlet
How to retreive data by using combo box value - JSP-Servlet
How to retreive data by using combo box value - JSP-Servlet
Retrieving Data from Database to fill Combo Box
how to retrieve data into combo from database in java applet?
how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/
how to retrieve data from database ?????/
how to retrieve data from database ?????/
How to Retrieve Data from the database and write into excel file using Java
Retrieving data from data base using jsp combo box
how can retrive value from combo box in servlet?
retrieve data from database using jsf
how to use bean to retrieve data from database
How to Retrieve Data from Facebook Using PHP
How to Retrieve Data from Facebook Using PHP
retrieving from oracle database using jsp combo box
retrieve related data from database using jsp and mysql
Retrieve data from database by using sql tag of JSTL SQL library
how to get combo box value - JSP-Servlet
How to show autocomplete textbox values on combo box option selection using database?

Ads