這幾天忙著整理搞ISO的文檔,也不知道自己維護的數據庫手冊是否齊全,算了干脆寫個程序全給導出來算了;)。下面的程序expddl.jsp可導出當前連接數據庫的用戶下的所有數據表的DDL.
EXPDDL.JSP:
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<%@ page import = "java.sql.*" %>
<%@ page import = "oracle.jdbc.OracleDatabaseMetaData" %>
<%@ page import = "oracle.jdbc.OracleResultSetMetaData" %>
<%@ page import = "javax.sql.*,javax.naming.Context" %>
<%@ page import = "javax.naming.InitialContext" %>
<div align="center">
<%
DataSource ds = null;
Context ic = new InitialContext();
ds = (DataSource) ic.lookup("java:comp/env/jdbc/mydb");
Connection conn = ds.getConnection();
OracleDatabaseMetaData odmd = (OracleDatabaseMetaData) conn.getMetaData();
String us = odmd.getUserName();
String[] types = new String[1];
types[0] = "TABLE";
ResultSet rs = odmd.getTables(null,us,"%",types);
while(rs.next()) {
//取表名
String tname = rs.getString(3);
%>
<div align="center">表名:<%= tname%></div>
<table width="483" height="50" border="1" cellpadding="2" cellspacing="0">
<tr>
<td><div align="center">序號</div></td>
<td><div align="center">標識</div></td>
<td><div align="center">類型/精度</div></td>
<td><div align="center">標識說明</div></td>
</tr>
<%
Statement st = conn.createStatement();
ResultSet rs1 = st.executeQuery("select * from " + tname);
OracleResultSetMetaData ormd = (OracleResultSetMetaData) rs1.getMetaData();