Exporting Oracle Data Tables Using JSP is a common operation during application development. How can this problem be achieved? Now let's start with our program introduction. First, the following program expddl. jsp can export the Oracle data table for the DDL of all data tables under the database user.
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 dmd = (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()) {
-
Name the Oracle Data Table exported from JSP
- StringTname=Rs. GetString (3 );
- %>
- <DivAlign="Center"> Table name: <%= tname % ></ div>
- <TableWidth="483" Height="50" Border="1" Cellpadding="2" Cellspacing="0">
- <Tr>
- <Td> <divAlign="Center"> NO. </div> </td>
- <Td> <divAlign="Center"> Identifier </div> </td>
- <Td> <divAlign="Center"> Type/precision </div> </td>
- <Td> <divAlign="Center"> Description </div> </td>
- </Tr>
- <%
- StatementSt=Conn. CreateStatement ();
- ResultSetRs1=St. ExecuteQuery ("select * from" + tname );
- OracleResultSetMetaDataRmd= (OracleResultSetMetaData) rs1.getMetaData ();
-
Total number of columns extracted from Oracle Data Tables exported by JSP
- int colcnt = ormd.getColumnCount();
-
Extract column numbers from Oracle Data Tables exported by JSP
- IntNum=1;
- For (intJ=0; J <colcnt; j ++ ){
- StringS=Ormd. GetColumnTypeName (j + 1). toLowerCase ();
-
- Only the varchar2 char date number type is processed for Oracle Data Tables (corresponding processing is added as needed)
-
- If (s. equals ("varchar2") | s. equals ("char") | s. equals ("date") | s. equals ("number ")){
- If (s. equals ("varchar2") | s. equals ("char "))
- SS= S + "(" + ormd. getColumnDisplaySize (j + 1) + ")";
- If (s. equals ("number "))
- SS= S + "(" + ormd. getPrecision (j + 1) + "," + ormd. getScale (j + 1) + ")";
- %>
- <Tr>
- <TdWidth="40"> <DivAlign="Center"><%= Num ++ % ></ div ></ td>
- <TdWidth="98"><% = Ormd. getColumnName (j + 1) % ></ td ><tdWidth="144"><%= S % ></ td>
- <TdWidth="173"></ Td ></ tr>
- <%
- }
- }
- Rs1.close ();
- St. close ();
- %>
- </Table>
- <Br>
- <%
- }
- Rs. close ();
- Conn. close ();
- %>
- </Div>
-
Through the above operations on Oracle Data Tables exported by JSP, do you have your own ideas on the implementation of this program?
- A brief overview of embedded objects in JSP
- Use JSP include mechanism to improve appearance
- Six common issues for JSP Programming
- JSP tutorial basics: Technical Features of JSP
- Specific algorithms for implementing the tree structure of JSP forums