此程序是根据输入不同的信息登陆ORACLE数据库或SQL数据库,并显示相对应的表名在下拉列表中,当选择下拉列表时候,在另一个文本域中显示对应的表字段信息:
附上代码片段databaseconnection.jsp:(新手写的很乱,请见谅)
......
<title>数据库信息显示</title>
<script language="javascript">
function changetable()
{
var ta_name = document.getElementById("select").value;
"<%=t_Name%>"=ta_name;
alert("<%=t_Name%>");
}
function toMove()
{
var s_left = document.frmselect.selectleft;
var s_rigt = document.frmselect.selectrigth;
for(i=0;i<s_left.length;i++)
{
if(s_left.options[i].selected)
{
s_rigt[s_rigt.length++].text = s_left.options[i].text;
s_left.remove(s_left.selectedIndex);
i--;
}
}
}
function toRemove()
{
var s_left = document.frmselect.selectleft;
var s_rigt = document.frmselect.selectrigth;
for(i=0;i<s_rigt.length;i++)
{
if(s_rigt.options[i].selected)
{
s_left[s_left.length++].text = s_rigt.options[i].text;
s_rigt.remove(s_rigt.selectedIndex);
i--;
}
}
}
</script>
</head>
<body>
<table width="90%" border="1" align="center" bordercolor="#66CCFF">
<tr>
<td width="21%">数据库类型:</td>
<td colspan="2"><%=request.getAttribute("databaseType")%></td>
<td width="16%">服务器地址:</td>
<td width="27%"><%=request.getAttribute("dbname")%></td>
</tr>
<tr>
<td colspan="2">当前数据库名称(或SID):</td>
<td width="27%"><%=request.getAttribute("dbsouse")%></td>
<td>登陆帐号:</td>
<td><%=request.getAttribute("username")%></td>
</tr>
</table>
<br/><br/>
<table width="90%" border="0" align="center">
<tr>
<td width="31%"> </td>
<td> </td>
<td width="37%"> </td>
</tr>
<tr>
<td><div align="right">此对象所包括的表为:</div></td>
<td width="32%">
<form name="totable" action="">
<select name="select" id="select" style="width:100% " onchange="changetable()">
<%
List tables = (List)request.getAttribute("tables");
Iterator itr = tables.iterator();
int x = 0;
while(itr.hasNext())
{
String tname = (String)itr.next();
%>
<--这里显示的就是登陆数据库所对应的所有表名!!-->
<option value="<%=tname%>"><%=tname%></option>
<%
}
x++;
%>
</select>
</form></td>
<td> </td>
</tr>
</table>
<form action="" name="frmselect">
<table width="60%" style="border:double" bordercolor="#CCCCCC" align="center">
<tr>
<td width="43%" align="center" valign="top"><label>
<select name="selectleft" size="15" style="width:90%" multiple="multiple">
<%
DBinfoBean dbean = (DBinfoBean)request.getAttribute("todb");
ShowColumn sc = new ShowColumn(dbean);
List col = (List)sc.getColName(t_Name);//此t_Name,在页面顶部声明,就是下拉列表传入的某个值,我不知道如何传入。
Iterator it = col.iterator();
while(it.hasNext())
{
String colname = (String)it.next();
%>
<option><%=colname%></option>//此处即为此表对应的所有字段名称!!
<%
}
%>
</select>
</label></td>
<td width="14%" align="center"><label>
<input type="button" style="width:30pt" name="button" id="button" value=">>" onclick="toMove()" />
<br />
<br />
<br />
<br />
<br />
<br />
<input type="button" style="width:30pt" name="button" id="button" value="<<" onclick="toRemove()"/>
</label></td>
<td width="43%" align="center" valign="top"><label>
<select name="selectrigth" size="15" style="width:90%" multiple="multiple" id="select3">
</select>
</label></td>
</tr>
</table>
</form>
<p> </p>
<p> </p>
</body>
</html>