ddddd
<%@ 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
總結
- 上一篇: IOS应用内支付IAP从零开始详解
- 下一篇: 《实施Cisco统一通信管理器(CIPT