请大家帮我看看这个程序!!

LoveLL810625 2004-03-26 09:58:15
这是一个JSP页面,它包括两个下拉列表的动态关联

<%@ page contentType = "text/html;charset = SJIS" %>//编码方式为日语
<%@ page import = "java.sql.*" %>
<%
Connection con = null;
Statement stmt = null;
ResultSet rs1 = null;
ResultSet rs2 = null;
String SID = null;
try{ //连接数据库
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:Kigyo_jyoho_kanri","","");
stmt = con.createStatement();
rs1 = stmt.executeQuery("SELECT * FROM Mst_China_Sho"); //
rs2 = stmt.executeQuery("SELECT * FROM Mst_China_Toshi");
}
catch(SQLException e) {}
%>
<html>
<body>
<form name = "form1" method = "post" action = "process.jsp">
<select name = "ShoName" onchange = "showToshi()">
<option value = "0" selected>请选择</option>
<%
while (rs1.next()) {
SID = rs1.getString("Sho_Code");
%>
<option value = "<%= rs1.getString("Sho_Code")%>"><%= rs1.getString("Sho_Name")%></option>
<%
}
rs1.close();
%>
</select>
<SCRIPT LANGUAGE="JavaScript">
Toshi_Name = new Array();
Toshi_Code = new Array();
<%
int count = 0;
while (rs2.next()) {
String toshi_id = rs2.getString("Toshi_Code");
String toshi_name = rs2.getString("Toshi_Name");
out.println("Toshi_Name["+count+"] = "+ toshi_name );
out.println("Toshi_Code["+count+"] = "+ toshi_id );
count++;
}
rs2.close();
%>
function showToshi(){
selected = document.form1.ShoName.selectedIndex;
if (selected == 0) {
document.form1.ToshiName.length = 0;
document.form1.ToshiName.length++;
document.form1.ToshiName.options[document.form1.ToshiName.length-1].value="0";
document.form1.ToshiName.options[document.form1.ToshiName.length-1].text="お選んでください";
return ;
}

index = document.form1.ShoName.options[selected].value;
document.form1.ToshiName.length = 0;
for(i=0;i<Toshi_Name.length;i++){
if (Toshi_Code[i].indexOf(index) != -1) {
document.form1.ToshiName.length++;
document.form1ToshiName.options[document.form1.ToshiName.length-1].value = Toshi_Code[i];
document.form1ToshiName.options[document.form1.ToshiName.length-1].text =Toshi_Name[i];
}
}
}
</SCRIPT>
<SELECT NAME="ToshiName">
<option value="0" selected>请选择</option>
</SELECT>
</form>
</body>
</html>

编译时发生错误!!!
...全文
63 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
King6860 2004-03-26
  • 打赏
  • 举报
回复
stmt = con.createStatement();
rs1 = stmt.executeQuery("SELECT * FROM Mst_China_Sho");
rs2 = stmt.executeQuery("SELECT * FROM Mst_China_Toshi");

因为STATEMENT 对象执行SQL 查询的时候,只能打开当前的记录集,在你的例子中,
目前只有RS2 是打开的,而RS1 已经关闭了。
你的异常可能是 :ResultSet Object has been closed.
gks_cn 2004-03-26
  • 打赏
  • 举报
回复
jsp里面代码太多一般会难以调试。
建议你把你的方法风状成工具类。好些。
liutang2 2004-03-26
  • 打赏
  • 举报
回复
把错误贴出来会好一些1

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧