
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

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
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.