<%
try
{
//以下几项请自行修改
String spath= "myprog\\DataBase\\db1.mdb "; //注意由网站根到文件的路径
String dbpath = application.getRealPath(spath); //转化成物理路径
String dbname = " "; //Acess 数据库用户名,没有则为空
String user = " "; //Acess 数据库密码,没有则为空
//数据库连接字符串
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ= "+dbpath;
//加载驱动程序
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
//建立连接
Connection conn= DriverManager.getConnection(url);
//创建语句对象
Statement stmt=conn.createStatement
(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
Statement stmt1=conn.createStatement
(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
Statement stmt2=conn.createStatement
(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String SelectStr = " ";
String sql1,sql2,sql3;
int i1,i2,i3;
//一级分类开始
sql1 = "select c1id,c1name from class1 ";
ResultSet rs1 = stmt.executeQuery(sql1);
i1 = 0;
while (rs1.next())
{
if (i1 > 0 )
{SelectStr = SelectStr + "|| ";}
else
{SelectStr = SelectStr + rs1.getString( "c1name ") + "{{ ";}
//显示与值不同时,用下面一行
//SelectStr = SelectStr + rs1( "c1name ") + "@ "+ rs1( "c1id ") + "{{ "
//二级分类开始
sql2 = "select c2id,c2name from class2 where c1name = ' "+ rs1.getString( "c1name ") + " ' ";
ResultSet rs2 = stmt1.executeQuery(sql2);
i2 = 0;
while (rs2.next())
{
if (i2 > 0)
{SelectStr = SelectStr + "** ";}
else
{SelectStr = SelectStr + rs2.getString( "c2name ") + "(( ";}
//显示与值不同时,用下面一行
//SelectStr = SelectStr + rs2( "c2name ") + "@ "+ rs2( "c2id ") + "(( "
//三级分类开始
sql3 = "select c3id,c3name from class3 where c2name = ' "+ rs2.getString( "c2name ")+ " ' ";
ResultSet rs3 = stmt2.executeQuery(sql3);
i3 = 0;
while (rs3.next())
{
if (i3 > 0 )
{SelectStr = SelectStr + "^ ";}
else
{SelectStr = SelectStr + rs3.getString( "c3name ");}
//显示与值不同时,用下面一行
//SelectStr = SelectStr + rs3( "c3name ") + "@ " + rs3( "c3id ")
i3 = i3 + 1;