亚洲城ca88

當前位置:

用JSP導出ORACLE的數據表DDL

2019/06/19 來源:亚洲城ca88

導讀

下麵的程序p可導出當前連接數據庫的用戶下的所有數據表的DDL.P:%@ page contentType="text/html; c

  下麵的程序p可導出當前連接數據庫的用戶下的所有數據表的DDL.

  P:

  %@ page contentType="text/html; charset=gb2312" language="java" %

  %@ page import = "l.*" %

  %@ page import = "acleDatabaseMetaData" %

  %@ page import = "acleResultSetMetaData" %

  %@ page import = "l.*,ntext" %

  %@ page import = "itialContext" %

  div align="center"

  %

  DataSource ds = null;

  Context ic = new InitialContext();

  ds = (DataSource) okup("java:comp/env/jdbc/mydb");

  Connection conn = tConnection();

  OracleDatabaseMetaData odmd = (OracleDatabaseMetaData) tMetaData();

  String us = tUserName();

  String[] types = new String[1];

  types[0] = "TABLE";

  ResultSet rs = tTables(null,us,"%",types);

  while(xt()) {

  //取表名

  String tname = tString(3);

  %

  div align="center"表名:%= tname%/div

  table width="483" height="50" border="1" cellpadding="2" cellspacing="0"

  tr

  tddiv align="center"序號/div/td

  tddiv align="center"標識/div/td

  tddiv align="center"類型/精度/div/td

  tddiv align="center"標識說明/div/td

  /tr

  %

  Statement st = eateStatement();

  ResultSet rs1 = ecuteQuery("select * from " + tname);

  OracleResultSetMetaData ormd = (OracleResultSetMetaData) tMetaData();

  //取列總數

  int colcnt = tColumnCount();

  //列序號

  int num = 1;

  for(int j=0;jcolcnt;j++) {

  String s = tColumnTypeName(j+1).toLowerCase();

  //隻處理varchar2 char date number類型(根據需要添加相應的處理)

  if(uals("varchar2") || uals("char") || uals("date") || uals("number")) {

  if(uals("varchar2") || uals("char"))

  s = s + "(" + tColumnDisplaySize(j+1) + ")";

  if(uals("number"))

  s = s + "(" + tPrecision(j+1) + "," + tScale(j+1) + ")";

  %

  tr

  td width="40"div align="center"%= num++ %/div/td

  td width="98"%=tColumnName(j+1)%/tdtd width="144"%= s %/td

  td width="173"/td /tr

  %

  }

  }

  ose();

  ose();

  %

  /table

  br

  %

  }

  ose();

  ose();

  %

  /div查看本文來源

小兒便秘吃什麽藥
腹瀉寶寶的飲食調理
寶寶吃四磨湯注意事項
標簽