home *** CD-ROM | disk | FTP | other *** search
- Save Format v2.0(1)
- @begin ClassFile "DJDBC_LookUp"
- Exported 0;
- Abstract 0;
- Interface 0;
- PackageName "";
- Language "Java";
-
- @begin UserFunction "DJDBC_LookUp()"
- Compiler 1;
- GencodeSrcLine 12;
- FunctionName "DJDBC_LookUp::DJDBC_LookUp()";
- @end;
-
- @begin UserFunction "main(String args[])"
- Compiler 1;
- GencodeFunction 1;
- GencodeSrcLine 16;
- FunctionName "DJDBC_LookUp::main(String args[])";
- @end;
-
- @begin UserFunction "CreateMainForm()"
- Compiler 1;
- GencodeFunction 1;
- GencodeSrcLine 23;
- FunctionName "DJDBC_LookUp::CreateMainForm()";
- @end;
-
- @begin UserFunction "StartApp(String args[])"
- Compiler 1;
- GencodeSrcLine 26;
- FunctionName "DJDBC_LookUp::StartApp(String args[])";
- @end;
-
- @begin UserFunction "RunApp(String args[])"
- Compiler 1;
- GencodeSrcLine 39;
- FunctionName "DJDBC_LookUp::RunApp(String args[])";
- @end;
-
- @begin UserFunction "EndApp(String args[])"
- Compiler 1;
- GencodeSrcLine 144;
- FunctionName "DJDBC_LookUp::EndApp(String args[])";
- @end;
-
- @begin HPPPrefixBlock
- @begin-code HPPPrefix
-
- // add your custom import statements here
- import java.io.*;
- import java.sql.*;
-
- @end-code;
- GencodeSrcLine 6;
- @end;
-
- @begin ClassContentsBlock
- @begin-code ClassContents
-
- // add your data members here
- DynamoConnection dynamo;
- Document document;
- DBConnection connection;
- Session session;
-
- @end-code;
- GencodeSrcLine 147;
- @end;
-
- @begin-code BaseClassList
-
- extends Object
-
- @end-code;
-
- @begin-code GeneratedClassContents
-
-
- @end-code;
-
- @begin-code Code "DJDBC_LookUp::DJDBC_LookUp()"
-
- public @CLASSNAME@()
- {
- super();
- }
-
- @end-code;
-
- @begin-code Code "DJDBC_LookUp::main(String args[])"
-
- public static void main(String args[])
- {
- @@CLASSNAME@ app = new @CLASSNAME@();
- app.StartApp(args);
- app.RunApp(args);
- app.EndApp(args);
- }
-
- @end-code;
-
- @begin-code Code "DJDBC_LookUp::CreateMainForm()"
-
- public void CreateMainForm()
- {
- }
-
- @end-code;
-
- @begin-code Code "DJDBC_LookUp::StartApp(String args[])"
-
- public void StartApp(String args[])
- {
- dynamo = new DynamoConnection( args );
- if(! dynamo.getConnected() ) {
- System.err.println( "Connection to NetImpact Dynamo failed" );
- System.exit(2);
- }
- // Define wrapper classes
- document = dynamo.getDocument();
- connection = dynamo.getDBConnection();
- session = dynamo.getSession();
-
- }
-
- @end-code;
-
- @begin-code Code "DJDBC_LookUp::RunApp(String args[])"
-
- public void RunApp(String args[])
- {
- //CreateMainForm();
- try {
- // Printing out headers
- document.writeln( "<CENTER><H1>JDBC Dynamo LookUp Sample</CENTER></H1>" );
- document.writeln( "<P>\n<BR>\n<HR>\n<BR>" );
-
- // Trying to load the Sybase JDBC Driver
- Class.forName( "com.sybase.jdbc.SybDriver" );
-
- // Creating the URL from the 'host' and 'port' specified
- String urlBase = "jdbc:sybase:Tds:";
- String host = args[1];
- String port = args[2];
- String firstName = args[3];
- String lastName = args[4];
- String userId = "dba";
- String password = "sql";
-
-
- String query = "SELECT * FROM DBA.customer WHERE";
- if( firstName != null ) {
- query = query + " customer.fname = \'" + firstName +"\'";
- if( lastName != null ) {
- query = query + " AND customer.lname = " + "\'" + lastName + "\'";
- }
- } else {
- query = query + " customer.lname = " + "\'" + lastName + "\'";
-
- }
-
- String url = urlBase + host + ":" + port;
- document.write( "<P>Trying to connect to: " );
- document.writeln( url );
-
- // Connect to the database at that URL.
- Connection _conn = DriverManager.getConnection( url, userId, password );
- Statement _stmt = _conn.createStatement();
-
- // Execute the query
- document.write( "<P>Sending query: " );
- document.write( query );
- document.writeln( "<BR>" );
- ResultSet _rs = _stmt.executeQuery( query );
-
- // Print out the customer's info
- _rs.next();
- document.writeln( "<H2><em>Customer Information</em></H2>" );
-
- document.writeln("<Normal>");
- document.write( "<P><strong>First Name</strong>: ");
- document.writeln( _rs.getString( 2 ) );
- document.write( "<P><strong>Last Name</strong>: " );
- document.writeln( _rs.getString( 3 ) );
- document.write( "<P><strong>Address</strong>: " );
- document.writeln( _rs.getString( 4 ) );
- document.write( "<P><strong>City</strong>: " );
- document.writeln( _rs.getString( 5 ) );
- document.write( "<P><strong>State</strong>: " );
- document.writeln( _rs.getString( 6 ) );
- document.write( "<P><strong>Zip</strong>: " );
- document.writeln( _rs.getString( 7 ) );
- document.write( "<P><strong>Phone</strong>: " );
- document.writeln( _rs.getString( 8 ) );
- document.write( "<P><strong>Company Name</strong>: " );
- document.writeln( _rs.getString( 9 ) );
- document.write( "<P><strong>Id</strong>: " );
- document.writeln( _rs.getString( 1 ) );
- document.writeln("</Normal>");
-
-
- // Closing the result set statement and the connection
- if( _rs != null ) {
- _rs.close();
- }
-
- if( _stmt != null ) {
- _stmt.close();
- }
-
- if( _conn != null ) {
- _conn.close();
- }
-
- document.writeln( "<P>\n<BR>\n<HR>\n<BR>" );
-
-
- } catch( DynamoException e ) {
- PrintException( "DynamoException: " + e.getMessage() );
- } catch( ClassNotFoundException e ) {
- PrintException( "ClassNotFoundException: " + e.getMessage() );
- } catch( SQLException e ) {
- PrintException( "SQLException: " + e.getMessage() );
- }
-
- }
-
- private void PrintException( String message )
- {
- try {
- document.writeln( "<FONT COLOR=\"red\">" + message + "</FONT>" );
- } catch( DynamoException e ) {
- }
- }
-
- @end-code;
-
- @begin-code Code "DJDBC_LookUp::EndApp(String args[])"
-
- public void EndApp(String args[])
- {
- }
-
- @end-code;
- @end;
-