急,联动下拉框,,不知道哪里错了,帮忙修改下!
联动下拉框,一个JAVA文件,一个JSP文件.
表结构 A,表 id varchar2(10),name varchar2(10)
B 表 id varchar2 ,name varchar2(10)
A表内容: 1 电脑, 2 空调 3 家电
B表内容:1 联想,1 方正,2 海尔, 2 春兰 , 3 LG,3 TCL
package DataBase;
import java.sql.*;
public class MyDbBean {
Connection con=null;
public MyDbBean() {
try {
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
con=DriverManager.getConnection( "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=zhucen ", "sa ", " ");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public ResultSet executeQuery (String sql) {
PreparedStatement pstm=null;
ResultSet rs=null;
try {
pstm=con.prepareStatement(sql);
rs=pstm.executeQuery();
return rs;
}
catch(SQLException e){
e.printStackTrace();
return null;
}catch (Exception e) {
e.printStackTrace();
return null;
}
finally{
try{
if(rs!=null)rs.close();
}catch(Exception e){}
}
}
}
<%@ page contentType= "text/html; charset=GBK " %>
<%@ page import= "DataBase.* " %>
<%@ page import= "java.sql.* " %>
<%! MyDbBean bean = new MyDbBean();%>
<html>
<head>
<title>
test
</title>
</head>
<body bgcolor= "#ffffff ">
<form method= "post " >
<select name= "dl " onChange= "javascript:window.location=(this.options[this.selectedIndex].value1) ">
<%
String id = request.getParameter( "id ");
String cSql = "select * from a ";
ResultSet sqlRst=bean.executeQuery(cSql);
try
{
while(sqlRst.next())
{
String i = sqlRst.getString( "id ");
String name = sqlRst.getString( "name ");
if(id == null) id= "1 ";
if (id.equals(i))
{
String temp= "test.jsp?id= "+i+ "&name= "+name;
out.println( " <option value= "+i+ " value1= "+temp+ " selected> "+name+ " </option> ");
}
else
{
String temp= "test.jsp?id= "+i+ "&name= "+name;
out.println( " <option value= "+i+ " value1= "+temp+ "> "+name+ " </option> ");
}
}
}catch(Exception e)
{}
%>
</select>
<select name= "dl ">
<%
String Csql = null;
if (id == null)
{
Csql= "select * from b where id = 1 ";
}
else
{
Csql= "select * from b where id = " +id ;
}
sqlRst=bean.executeQuery(Csql);
try{
while(sqlRst.next())
{
String i = sqlRst.getString( "id ");
String name = sqlRst.getString( "name ");
if (id.equals(i))
{
String temp= "test.jsp?id= "+i+ "&name= "+name;
out.println( " <option value= "+i+ " value1= "+temp+ " selected> "+name+ " </option> ");
}
else
{
String temp= "test.jsp?id= "+i+ "&name= "+name;
out.println( " <option value= "+i+ " value1= "+temp+ "> "+name+ " </option> ");
}
}
}catch(Exception e)
{
}
%>
</select>
</form>
</body>
</html>
[解决办法]
写这么一大堆。,。。。。怎么看啊?
[解决办法]
错误信息