home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 October
/
Chip_1997-10_cd.bin
/
tema
/
sybase
/
powerj
/
samples.z
/
IJDBC_LookUp.wxc
< prev
next >
Wrap
Text File
|
1997-01-28
|
7KB
|
236 lines
Save Format v2.0(1)
@begin ClassFile "IJDBC_LookUp"
Exported 0;
Abstract 0;
Interface 0;
PackageName "";
Language "Java";
@begin UserFunction "IJDBC_LookUp()"
Compiler 1;
GencodeSrcLine 12;
FunctionName "IJDBC_LookUp::IJDBC_LookUp()";
@end;
@begin UserFunction "main(String args[])"
Compiler 1;
GencodeFunction 1;
GencodeSrcLine 16;
FunctionName "IJDBC_LookUp::main(String args[])";
@end;
@begin UserFunction "CreateMainForm()"
Compiler 1;
GencodeFunction 1;
GencodeSrcLine 23;
FunctionName "IJDBC_LookUp::CreateMainForm()";
@end;
@begin UserFunction "StartApp(String args[])"
Compiler 1;
GencodeSrcLine 26;
FunctionName "IJDBC_LookUp::StartApp(String args[])";
@end;
@begin UserFunction "RunApp(String args[])"
Compiler 1;
GencodeSrcLine 34;
FunctionName "IJDBC_LookUp::RunApp(String args[])";
@end;
@begin UserFunction "EndApp(String args[])"
Compiler 1;
GencodeSrcLine 136;
FunctionName "IJDBC_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
WebConnection server;
@end-code;
GencodeSrcLine 139;
@end;
@begin-code BaseClassList
extends Object
@end-code;
@begin-code GeneratedClassContents
@end-code;
@begin-code Code "IJDBC_LookUp::IJDBC_LookUp()"
public @CLASSNAME@()
{
super();
}
@end-code;
@begin-code Code "IJDBC_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 "IJDBC_LookUp::CreateMainForm()"
public void CreateMainForm()
{
}
@end-code;
@begin-code Code "IJDBC_LookUp::StartApp(String args[])"
public void StartApp(String args[])
{
server = new WebConnection(args);
if (! server.getConnected() ) {
System.err.println("Connection to Server failed");
System.exit(2);
}
}
@end-code;
@begin-code Code "IJDBC_LookUp::RunApp(String args[])"
public void RunApp(String args[])
{
//CreateMainForm();
try {
// Printing out headers
server.setResponseHeader( "Content-Type", "text/html" );
server.writeln( "<CENTER><H1>JDBC ISAPI / NSAPI LookUp Sample</CENTER></H1>" );
server.writeln( "\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 = null;
String port = null;
String firstName = null;
String lastName = null;
String userId = "dba";
String password = "sql";
if( server.getIsPostMethod() ) {
host = server.getFormVariable( "host" );
port = server.getFormVariable( "port" );
firstName = server.getFormVariable( "firstName" );
lastName = server.getFormVariable( "lastName" );
} else {
host = server.getQueryVariable( "host" );
port = server.getQueryVariable( "port" );
firstName = server.getQueryVariable( "firstName" );
lastName = server.getQueryVariable( "lastName" );
}
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;
server.write( "<P>Trying to connect to: " );
server.writeln( url );
// Connect to the database at that URL.
Connection _conn = DriverManager.getConnection( url, userId, password );
Statement _stmt = _conn.createStatement();
// Execute the query
server.write( "<P>Sending query: " );
server.write( query );
server.writeln( "<BR>" );
ResultSet _rs = _stmt.executeQuery( query );
// Print out the customer's info
_rs.next();
server.writeln( "<H2><em>Customer Information</em></H2>" );
server.writeln("<Normal>");
server.write( "<P><strong>First Name</strong>: ");
server.writeln( _rs.getString( 2 ) );
server.write( "<P><strong>Last Name</strong>: " );
server.writeln( _rs.getString( 3 ) );
server.write( "<P><strong>Adress</strong>: " );
server.writeln( _rs.getString( 4 ) );
server.write( "<P><strong>City</strong>: " );
server.writeln( _rs.getString( 5 ) );
server.write( "<P><strong>State</strong>: " );
server.writeln( _rs.getString( 6 ) );
server.write( "<P><strong>Zip</strong>: " );
server.writeln( _rs.getString( 7 ) );
server.write( "<P><strong>Phone</strong>: " );
server.writeln( _rs.getString( 8 ) );
server.write( "<P><strong>Company Name</strong>: " );
server.writeln( _rs.getString( 9 ) );
server.write( "<P><strong>Id</strong>: " );
server.writeln( _rs.getString( 1 ) );
server.writeln("</Normal>");
// Closing the statement and the connection
if( _stmt != null ) {
_stmt.close();
}
if( _conn != null ) {
_conn.close();
}
server.writeln( "<P>\n<BR>\n<HR>\n<BR>" );
} catch( WebServiceException e ) {
server.writeln( "<H2>WebService Exception: " + e.getMessage() );
} catch( ClassNotFoundException e ) {
server.writeln( "<H2>ClassNotFound Exception: " + e.getMessage() );
} catch( Exception e ) {
server.writeln( "<H2>Unexpected Exception: " + e.getMessage() );
}
}
@end-code;
@begin-code Code "IJDBC_LookUp::EndApp(String args[])"
public void EndApp(String args[])
{
}
@end-code;
@end;