The Code Sample of Index Listing


The following program is used to implement the button “List indexes” of the previous interface.

~/public_html/cgi-bin/515/week2/List.java
 /********************************************************
 
    SQL> CREATE TYPE  url_title  AS OBJECT (
      2    url    VARCHAR(128),
      3    title  VARCHAR(128) );
 
    SQL> CREATE TYPE  urls_typ  AS TABLE OF  url_title;
 
    SQL> CREATE TABLE  www_index (
      2    keyword   VARCHAR(64)  PRIMARY KEY,
      3    urls      urls_typ
      4  )  NESTED TABLE  urls  STORE AS  urls_tbl;
 
 ********************************************************/

 import  java.io.*;
 import  java.lang.*;
 import  java.sql.*;
 
 public class  List {
   public static void  main( String args[ ] )
     throws SQLException {
     DriverManager.registerDriver(
       new oracle.jdbc.driver.OracleDriver( ) );
     Connection conn = DriverManager.getConnection(
       "jdbc:oracle:thin:@134.129.213.35:1521:orcl", "userid", "password");

     try {
       String  query = "SELECT keyword, n.URL FROM www_index w,";
       query += " TABLE(w.urls) n WHERE ";
       query += "keyword like '%" + args[0] + "%' ORDER BY keyword";
       Statement  stmt = conn.createStatement( );
       ResultSet  rset = stmt.executeQuery( query );
 
       System.out.print( "<table width='80%' border='2'>" );
       System.out.print( "<tr><th width='25%'>Keyword" );
       System.out.print( "<th width='75%'>URL</th></tr>" );

       while ( rset.next( ) ) {  
         String  str = rset.getString( 1 );
         System.out.print( "<tr><td>" + str );
         str = rset.getString( 2 );
         System.out.print  ( "</td><td><a href='" + str + "'>" );
         System.out.println( str + "</a></td></tr>" );
       }
       System.out.print( "</table>" );
       rset.close( );
       stmt.close( );
     }
     catch ( SQLException ex ) {
       System.out.println( ex );
     }
     conn.close( );
   }
 }