This is a database dictionary page which has two drop-down boxes.
first - for the tables in the database(it displays all the table names in the dropdown.
Second - for the columns of the table selected in the previous dropdown
n then on selecting the column name it should display that particular column values of the in a table format.
in the code below i have not written the code to populate the results to the second drop down... i am jus checkin whether i m gettin the result back from columns.jsp(from where result has to come) or not.
problem is that i am not gettin back the result...
this is the first file from where asynchronous call is made to another file...i.e columns.jsp
index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<%@page import="bea.SqlConnection"%>
<%@page import="bea.Department"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language="JavaScript">
function getColumns(){
alert("hello");
var req;
if(window.XMLHttpRequest){
req=new XMLHttpRequest;
alert("hello0");
}
else{
try{
req=new ActiveXObject(Microsoft.XMLHTTP);
}
catch(e)
{
req=new ActiveXObject(Msxml2.XMLHTTP);
}
}
var n=document.frm.TABLES.selectedIndex;
alert("hello1");
var ca=document.frm.TABLES.options[n].value;
alert("hello2");
req.open("GET","http://localhost:8080/sampleajaz/columns.jsp?TABLES="+ca,true);
alert("hello3");
req.onreadystatechange=function updateTable(){
if(req.readyState==4 && req.status==200)
alert("hello4");
document.getElementById("dcc").innerHTML=req.responseText;
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form name="frm" action="columns.jsp">
<h1>Dictionary Window</h1>
<br>
<%
String q;
Connection cn=null;
PreparedStatement st=null;
ResultSet rst=null;
SqlConnection sq=new SqlConnection();
try{
q="select tname from tab";
Class.forName(sq.getName());
cn=DriverManager.getConnection(sq.getConnstr(),sq.getUser(),sq.getPwd());
st=cn.prepareStatement(q);
rst=st.executeQuery();
%>
<table align="center" border="0">
<tr><td>tables</td><td>:</td><td>
<select name="TABLES" onchange="getColumns()">
<%
while(rst.next()){
String dn=rst.getString("TNAME");
%>
<option value="<%=dn%>"><%=dn%></option>
<%
}}
catch(Exception e)
{
e.getMessage();
}
%>
</select>
</tr></table>
<div id="dcc"></div>
</form>
</body>
</html>
columns.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<%@page import="bea.SqlConnection"%>
<%@page import="bea.Department"%>
<%
String q,TA;
TA=request.getParameter("TABLES");
SqlConnection sq=new SqlConnection();
out.println(TA);
Connection cn=null;
PreparedStatement st=null;
ResultSet rst=null;
try{
q="SELECT COLUMN_NAME FROM ALL_TAB_COLS WHERE TABLE_NAME=?";
Class.forName(sq.getName());
cn=DriverManager.getConnection(sq.getConnstr(),sq.getUser(),sq.getPwd());
st=cn.prepareStatement(q);
st.setString(1,TA);
rst=st.executeQuery();
while(rst.next()){
String CO=rst.getString("COLUMN_NAME");
out.println(CO);
out.println("-");
}
}
catch(Exception e){
e.getMessage();
}
%>