当前位置: 代码迷 >> Java Web开发 >> jsp有关问题 哪位高手能帮小弟我解决一下多谢了
  详细解决方案

jsp有关问题 哪位高手能帮小弟我解决一下多谢了

热度:61   发布时间:2016-04-17 16:34:15.0
jsp问题 谁能帮我解决一下谢谢了
<%
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;
  相关解决方案