home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / samples.z / DJDBC_LookUp.wxc < prev    next >
Text File  |  1996-12-10  |  7KB  |  232 lines

  1. Save Format v1.3
  2. @begin ClassFile "DJDBC_LookUp"
  3.  Exported 0;
  4.  Abstract 0;
  5.  Interface 0;
  6.  PackageName "";
  7.  Language "Java";
  8.  
  9.  @begin UserFunction "DJDBC_LookUp()"
  10.   Compiler 1;
  11.   GencodeSrcLine 12;
  12.   FunctionName "DJDBC_LookUp::DJDBC_LookUp()";
  13.  @end;
  14.  
  15.  @begin UserFunction "main(String args[])"
  16.   Compiler 1;
  17.   GencodeFunction 1;
  18.   GencodeSrcLine 16;
  19.   FunctionName "DJDBC_LookUp::main(String args[])";
  20.  @end;
  21.  
  22.  @begin UserFunction "CreateMainForm()"
  23.   Compiler 1;
  24.   GencodeFunction 1;
  25.   GencodeSrcLine 23;
  26.   FunctionName "DJDBC_LookUp::CreateMainForm()";
  27.  @end;
  28.  
  29.  @begin UserFunction "StartApp(String args[])"
  30.   Compiler 1;
  31.   GencodeSrcLine 26;
  32.   FunctionName "DJDBC_LookUp::StartApp(String args[])";
  33.  @end;
  34.  
  35.  @begin UserFunction "RunApp(String args[])"
  36.   Compiler 1;
  37.   GencodeSrcLine 39;
  38.   FunctionName "DJDBC_LookUp::RunApp(String args[])";
  39.  @end;
  40.  
  41.  @begin UserFunction "EndApp(String args[])"
  42.   Compiler 1;
  43.   GencodeSrcLine 129;
  44.   FunctionName "DJDBC_LookUp::EndApp(String args[])";
  45.  @end;
  46.  
  47.  @begin HPPPrefixBlock
  48. @begin-code HPPPrefix
  49.  
  50. // add your custom import statements here
  51. import java.io.*;
  52. import java.sql.*;
  53.  
  54. @end-code;
  55.   GencodeSrcLine 6;
  56.  @end;
  57.  
  58.  @begin ClassContentsBlock
  59. @begin-code ClassContents
  60.  
  61.     // add your data members here
  62.     DynamoConnection dynamo;
  63.     Document    document;
  64.     DBConnection  connection;
  65.     Session session;
  66.  
  67. @end-code;
  68.   GencodeSrcLine 132;
  69.  @end;
  70.  
  71. @begin-code BaseClassList
  72.  
  73. extends Object
  74.  
  75. @end-code;
  76.  
  77. @begin-code GeneratedClassContents
  78.  
  79.  
  80. @end-code;
  81.  
  82. @begin-code Code "DJDBC_LookUp::DJDBC_LookUp()"
  83.  
  84.     public @CLASSNAME@()
  85.     {
  86.         super();
  87.     }
  88.  
  89. @end-code;
  90.  
  91. @begin-code Code "DJDBC_LookUp::main(String args[])"
  92.  
  93.     public static void main(String args[])
  94.     {
  95.         @@CLASSNAME@ app = new @CLASSNAME@();
  96.         app.StartApp(args);
  97.         app.RunApp(args);
  98.         app.EndApp(args);
  99.     }
  100.  
  101. @end-code;
  102.  
  103. @begin-code Code "DJDBC_LookUp::CreateMainForm()"
  104.  
  105.     public void CreateMainForm()
  106.     {
  107.     }
  108.  
  109. @end-code;
  110.  
  111. @begin-code Code "DJDBC_LookUp::StartApp(String args[])"
  112.  
  113.     public void StartApp(String args[])
  114.     {
  115.         dynamo = new DynamoConnection( args );
  116.         if(! dynamo.getConnected() ) {
  117.             System.err.println( "Connection to NetImpact Dynamo failed" );
  118.             System.exit(2);
  119.         }
  120.         // Define wrapper classes
  121.         document = dynamo.getDocument();
  122.         connection = dynamo.getDBConnection();
  123.         session = dynamo.getSession();
  124.  
  125.     }
  126.  
  127. @end-code;
  128.  
  129. @begin-code Code "DJDBC_LookUp::RunApp(String args[])"
  130.  
  131.     public void RunApp(String args[])
  132.     {
  133.         //CreateMainForm();
  134.         try {
  135.             // Printing out headers   
  136.             document.writeln( "<CENTER><H1>JDBC Dynamo LookUp Sample</CENTER></H1>" );
  137.             document.writeln( "<P>\n<BR>\n<HR>\n<BR>" );           
  138.           
  139.              // Trying to load the Sybase JDBC Driver
  140.             Class.forName( "com.sybase.jdbc.SybDriver" );
  141.                         
  142.             // Creating the URL from the 'host' and 'port' specified
  143.             String urlBase  = "jdbc:sybase:Tds:";
  144.             String host     = args[1];
  145.             String port     = args[2];
  146.             String userId   = "dba";
  147.             String password = "sql";            
  148.             String query    = "SELECT * FROM DBA.customer WHERE customer.id = 101";
  149.               
  150.             String url = urlBase + host + ":" + port;
  151.             document.write( "<P>Trying to connect to: " );
  152.             document.writeln( url );
  153.             
  154.             // Connect to the database at that URL.
  155.             Connection _conn = DriverManager.getConnection( url, userId, password );           
  156.             Statement _stmt = _conn.createStatement();                    
  157.  
  158.             // Execute the query
  159.             document.write( "<P>Sending query: " );
  160.             document.write( query );
  161.             document.writeln( "<BR>" );
  162.             ResultSet _rs = _stmt.executeQuery( query );
  163.  
  164.             // Print out the customer's info
  165.             _rs.next();
  166.             document.writeln( "<H2><em>Customer Information</em></H2>" );
  167.             
  168.             
  169.             document.write( "<P><strong>Id</strong>: " );
  170.             document.writeln( _rs.getString( 1 ) );
  171.             document.write( "<P><strong>First Name</strong>: ");
  172.             document.writeln( _rs.getString( 2 ) );
  173.             document.write( "<P><strong>Last Name</strong>: " );
  174.             document.writeln( _rs.getString( 3 ) );
  175.             document.write( "<P><strong>Adress</strong>: " );
  176.             document.writeln( _rs.getString( 4 ) );
  177.             document.write( "<P><strong>City</strong>: " );
  178.             document.writeln( _rs.getString( 5 ) );
  179.             document.write( "<P><strong>State</strong>: " );
  180.             document.writeln( _rs.getString( 6 ) );
  181.             document.write( "<P><strong>Zip</strong>: " );
  182.             document.writeln( _rs.getString( 7 ) );
  183.             document.write( "<P><strong>Phone</strong>: " );
  184.             document.writeln( _rs.getString( 8 ) );
  185.             document.write( "<P><strong>Company Name</strong>: " );
  186.             document.writeln( _rs.getString( 9 ) );
  187.                        
  188.             // Closing the result set statement and the connection
  189.             if( _rs != null ) {
  190.                 _rs.close();
  191.             }
  192.             
  193.             if( _stmt != null ) {
  194.                 _stmt.close();
  195.             }
  196.  
  197.             if( _conn != null ) {
  198.                 _conn.close();
  199.             }
  200.                       
  201.             document.writeln( "<P>\n<BR>\n<HR>\n<BR>" );
  202.         
  203.              
  204.         } catch( DynamoException e ) {       
  205.             PrintException( "DynamoException: " + e.getMessage() );                
  206.         } catch( ClassNotFoundException e ) {
  207.             PrintException( "ClassNotFoundException: " + e.getMessage() );
  208.         } catch( SQLException e ) {
  209.             PrintException( "SQLException: " + e.getMessage() );
  210.         }
  211.  
  212.     }
  213.     
  214.     private void PrintException( String message ) 
  215.     {
  216.         try {
  217.             document.writeln( "<FONT COLOR=\"red\">" + message + "</FONT>" );  
  218.         } catch( DynamoException e ) {
  219.         }
  220.     }
  221.  
  222. @end-code;
  223.  
  224. @begin-code Code "DJDBC_LookUp::EndApp(String args[])"
  225.  
  226.     public void EndApp(String args[])
  227.     {
  228.     }
  229.  
  230. @end-code;
  231. @end;
  232.