How to export Oracle Data Tables Using JSP

Source: Internet
Author: User

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:

 
 
  1. ﹤%@ page contentType="text/html; charset=gb2312" language="java" %﹥  
  2. ﹤%@ page import = "java.sql.*" %﹥  
  3. ﹤%@ page import = "oracle.jdbc.OracleDatabaseMetaData" %﹥  
  4. ﹤%@ page import = "oracle.jdbc.OracleResultSetMetaData" %﹥  
  5. ﹤%@ page import = "javax.sql.*,javax.naming.Context" %﹥  
  6. ﹤%@ page import = "javax.naming.InitialContext" %﹥  
  7. ﹤div align="center"﹥  
  8. ﹤%  
  9. DataSource ds = null;  
  10.  
  11. Context ic = new InitialContext();  
  12. ds = (DataSource) ic.lookup("java:comp/env/jdbc/mydb");  
  13.  
  14. Connection conn = ds.getConnection();  
  15.  
  16. OracleDatabaseMetaData dmd = (OracleDatabaseMetaData) conn.getMetaData();  
  17. String us = odmd.getUserName();  
  18. String[] types = new String[1];  
  19. types[0] = "TABLE";  
  20. ResultSet rs = odmd.getTables(null,us,"%",types);  
  21. while(rs.next()) {  
  22.  

Name the Oracle Data Table exported from JSP

 
 
  1. StringTname=Rs. GetString (3 );
  2. %>
  3. <DivAlign="Center"> Table name: <%= tname % ></ div>
  4. <TableWidth="483" Height="50" Border="1" Cellpadding="2" Cellspacing="0">
  5. <Tr>
  6. <Td> <divAlign="Center"> NO. </div> </td>
  7. <Td> <divAlign="Center"> Identifier </div> </td>
  8. <Td> <divAlign="Center"> Type/precision </div> </td>
  9. <Td> <divAlign="Center"> Description </div> </td>
  10. </Tr>
  11. <%
  12. StatementSt=Conn. CreateStatement ();
  13. ResultSetRs1=St. ExecuteQuery ("select * from" + tname );
  14. OracleResultSetMetaDataRmd= (OracleResultSetMetaData) rs1.getMetaData ();
  15.  

Total number of columns extracted from Oracle Data Tables exported by JSP

 
 
  1. int colcnt = ormd.getColumnCount();  
  2.  

Extract column numbers from Oracle Data Tables exported by JSP

 
 
  1. IntNum=1;
  2. For (intJ=0; J <colcnt; j ++ ){
  3. StringS=Ormd. GetColumnTypeName (j + 1). toLowerCase ();
  4.  
  5. Only the varchar2 char date number type is processed for Oracle Data Tables (corresponding processing is added as needed)
  6.  
  7. If (s. equals ("varchar2") | s. equals ("char") | s. equals ("date") | s. equals ("number ")){
  8. If (s. equals ("varchar2") | s. equals ("char "))
  9. SS= S + "(" + ormd. getColumnDisplaySize (j + 1) + ")";
  10. If (s. equals ("number "))
  11. SS= S + "(" + ormd. getPrecision (j + 1) + "," + ormd. getScale (j + 1) + ")";
  12. %>
  13. <Tr>
  14. <TdWidth="40"> <DivAlign="Center"><%= Num ++ % ></ div ></ td>
  15. <TdWidth="98"><% = Ormd. getColumnName (j + 1) % ></ td ><tdWidth="144"><%= S % ></ td>
  16. <TdWidth="173"></ Td ></ tr>
  17. <%
  18. }
  19. }
  20. Rs1.close ();
  21. St. close ();
  22. %>
  23. </Table>
  24. <Br>
  25. <%
  26. }
  27. Rs. close ();
  28. Conn. close ();
  29. %>
  30. </Div>
  31.  

Through the above operations on Oracle Data Tables exported by JSP, do you have your own ideas on the implementation of this program?

  1. A brief overview of embedded objects in JSP
  2. Use JSP include mechanism to improve appearance
  3. Six common issues for JSP Programming
  4. JSP tutorial basics: Technical Features of JSP
  5. Specific algorithms for implementing the tree structure of JSP forums

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.