<%@ page contentType=”text/html;charset=gb2312″%>
<%@ page import=”java.sql.*,java.util.Date” errorPage=”../error.jsp”%>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
<title>jsp实现三级联动的下拉列表框效果</title>
<%
   Connection conn=null;
   Statement stmt=null;
   ResultSet rs=null,rs1=null,rs2=null;
   String sql;
   int count;
   int count2;
   String drivername=”com.microsoft.sqlserver.jdbc.SQLServerDriver”;
   String url=”jdbc:sqlserver://172.16.16.121:1433;DatabaseName=suppliers”;
   try{
    Class.forName(drivername);
    conn=DriverManager.getConnection(url,”sa”,”woods”);
    stmt=conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
    sql=”select * from V_CITY order by PCODE asc”; 
    rs=stmt.executeQuery(sql);
   }catch(SQLException e){
    System.out.println(e.getMessage());
   }
   
%>
<script language=”javascript”>
var onecount;
onecount=0;
subcat=new Array();
<%
count=0;
while(rs.next()){
 %>
 subcat[<%=count%>]=new Array(“<%=rs.getString(“NAME”)%>”,”<%=rs.getString(“PCODE”)%>”,”<%=rs.getString(“CODE”)%>”);
 <%
 count = count + 1 ; 

}
rs.close();
rs=null;
%>
onecount=<%=count%>;
function changelocation(locationid){
document.myform.smalllocation.length=0;
var locationid=locationid;
var i;
document.myform.smalllocation.options[0]=new Option(‘==所选城市的地区==’,”); 
for(i=0;i<onecount;i++){
if (subcat[i][1] == locationid) 

document.myform.smalllocation.options[document.myform.smalllocation.length] = new Option(subcat[i][0], subcat[i][2]); 



   
}
</script>
<%
 sql=”select * from V_VILLAGE order by CCODE asc”;
 rs2=stmt.executeQuery(sql);
%>
<script language=”javascript”>
var onecount2;
onecount2=0;
subcat2=new Array();
<%
count2=0;
while(rs2.next()){
 %>
 subcat2[<%=count2%>]=new Array(“<%=rs2.getString(“NAME”)%>”,”<%=rs2.getString(“CCODE”)%>”,”<%=rs2.getString(“CODE”)%>”);
 <%
 count2 = count2 + 1 ; 

}
rs2.close();
rs2=null;
%>
onecount2=<%=count2%>;
function changelocation2(districtid) 

document.myform.village.length = 0; 

var districtid=districtid; 
var j; 
document.myform.village.options[0] = new Option(‘==所选地区的县区==’,”); 
for (j=0;j < onecount2; j++) 

  if (subcat2[j][1] == districtid) 
 { 
  document.myform.village.options[document.myform.village.length] = new Option(subcat2[j][0], subcat2[j][2]); 
  } 



</script> 

</head>
<body>
<form name=”myform” method=”post”> 
分类:<select name=”biglocation” onChange=”changelocation(document.myform.biglocation.options[document.myform.biglocation.selectedIndex].value)” size=”1″> 
<option selected>请选择你所在的省份</option> 
<% 
  sql =”select * from V_PROVINCE order by CODE asc”;
 rs1 = stmt.executeQuery(sql);
 while(rs1.next()){
 %> 
 <option value=”<%=rs1.getString(“CODE”)%>”><%=rs1.getString(“NAME”)%></option> 

 <% }
 
 
 rs1.close(); 
 rs1 = null; 
 conn.close();
 conn =null; 

%> 
</select><select name=”smalllocation” onChange=”changelocation2(document.myform.smalllocation.options[document.myform.smalllocation.selectedIndex].value)”> 
<option selected value=””>==所有地区==</option> 
</select><select name=”village” size=”1″> 
<option selected>==所有县区==</option> 
</select> 
</form> 

</body>
</html>

  Private Sub Form_Load()
  ‘创建Connection对象cnn,关键New用于创建新对象
  Dim cnn As New ADODB.Connection
  Dim rs As New ADODB.Recordset
  ‘设置连接字符串
  cnn.ConnectionString = “Provider=SQLOLEDB.1;User ID=sa;” _
            + “Password=123456;Initial Catalog=test;Data Source=10.85.30.97”
 
  ‘打开到数据库的连接
  cnn.Open
  ‘判断连接的状态
  If cnn.State = adStateOpen Then
    ‘如果连接成功,则显示OK
    MsgBox “打开数据库”
  End If
  ‘关闭连接
  cnn.Close
  ‘判断连接的状态
  If cnn.State = adStateClosed Then
    ‘如果连接成功,则显示OK
    MsgBox “关闭数据库”
  End If
End Sub