国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

利用JDBC顯示數據庫詳細信息---JSP實現

2024-09-05 00:19:19
字體:
來源:轉載
供稿:網友

本來打算在控制臺就ok了!但是效果不好看!在jsp上面寫了一個管理類!還沒有完全完工的!就是顯示數據庫表 存儲過程 還有基本信息而已...代碼如下 

//database manager class
class dbm{
    private javax.servlet.jsp.jspwriter out;
    private connection con;
    private statement stmt;
    private resultset rs;
    public dbm(string drivername,string url,string username,string password,javax.servlet.jsp.jspwriter out)throws exception{
        class.forname(drivername);
        this.out=out;
        con=drivermanager.getconnection(url,username,password);
    }
    public void lookinfo()throws exception{
     databasemetadata dbmd=con.getmetadata();
     string tabletype=null;
     out.print("<strong>databaseinfo</strong><table>");
     out.print("<tr><td>databasename:</td><td>"+dbmd.getdatabaseproductname()+"</td></tr>");
     out.print("<tr><td>databaseversion:</td><td>"+dbmd.getdatabaseproductversion()+"</td></tr>");
     out.print("<tr><td>the numeric function:</td><td>"+dbmd.getnumericfunctions()+"</td></tr>");
     out.print("<tr><td>the string function:</td><td>"+dbmd.getstringfunctions()+"</td></tr>");
     out.print("<tr><td>the timedate function:</td><td>"+dbmd.gettimedatefunctions()+"</td></tr>");
     out.print("<tr><td>the system function:</td><td>"+dbmd.getsystemfunctions()+"</td></tr>");
     out.print("</table>");
     out.print("<strong>procedureinfo</strong><table>");
     getproceduredetail(dbmd.getprocedures(null,null,null));
     //show  all the tables
     try{
      rs=dbmd.gettables(null,null,null,null);
     }catch(exception proe){}
     out.print("<strong>database tables info</strong><br>");
     while(rs.next()){
      tabletype=rs.getstring(4);
      out.print("<strong>tablename:</strong>"+rs.getstring(3)+" <strong>type:</strong>"+tabletype+"<br>");
      if(tabletype.indexof("view")>=0||tabletype.indexof("table")>=0){
       try{
        gettabledetail(dbmd.getcolumns(null,null,rs.getstring(3),null));
       }catch(exception columne){}
      }
     }
     this.closeall();
    }
    //show the column information
    private void gettabledetail(resultset tablers)throws exception{
        out.print("<table border=1><tr><td>column_name</td><td>data_type</td><td>type_name</td><td>column_size</td><td>is_nullable</td><td>char_octet_length</td></tr>");
        while(tablers.next()){
            out.print("<tr><td>"+tablers.getstring(4)+"</td><td>"+tablers.getint(5)+"</td><td>"+tablers.getstring(6)+"</td><td>"+tablers.getint(7)+"</td><td>"+tablers.getstring(18)+"</td><td>"+tablers.getint(16)+"</td></tr>");
        }
        out.print("</table>");
        tablers.close();
    }
    //show all the procedures
    private void getproceduredetail(resultset procrs)throws exception{
     out.print("<table border=1><tr><td>procedure_name</td><td>remarks</td><td>procedure_type</td></tr>");
     while(procrs.next()){
      out.print("<tr><td>"+procrs.getstring(3)+"</td><td>"+procrs.getstring(7)+"</td><td>"+procrs.getshort(8)+"</td></tr>");
     }
     out.print("</table>");
     procrs.close();
    }
    //close all the resource
    private void closeall()throws sqlexception{
        try{
            if(rs!=null)rs.close();
        }catch(exception e){
        }
        try{
            if(stmt!=null)stmt.close();
        }catch(exception e){
        }
        try{
         if(con!=null)con.close();
        }catch(exception e){
        }
    }
}

------------

構造函數傳入 驅動類 還有連接url 用戶 密碼  然后調用lookinfo 方法就ok了!


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 咸阳市| 乌审旗| 泉州市| 怀仁县| 娄烦县| 称多县| 巴南区| 岱山县| 博乐市| 东乌珠穆沁旗| 漯河市| 深圳市| 宽甸| 武邑县| 南汇区| 卢湾区| 成安县| 巩留县| 贺州市| 于都县| 乐亭县| 宾川县| 项城市| 奉化市| 新干县| 财经| 青州市| 秦安县| 毕节市| 九江县| 仲巴县| 屯门区| 靖宇县| 丽水市| 内丘县| 五指山市| 东兰县| 徐水县| 沂水县| 藁城市| 射洪县|