/*******************************************************************
* *
* This program shows how to use simple CGI. *
* *
*******************************************************************/
// Import the following packages to use JDBC.
import java.sql.*;
import java.io.*;
import oracle.jdbc.*;
import oracle.jdbc.pool.OracleDataSource;
class test {
public static void main( String args[ ] ) throws SQLException {
String user = "C##user_id";
String password = "password";
String database = "20.185.147.112:1521/xe";
// Open an OracleDataSource and get a connection.
OracleDataSource ods = new OracleDataSource( );
ods.setURL ( "jdbc:oracle:thin:@" + database );
ods.setUser ( user );
ods.setPassword( password );
Connection conn = ods.getConnection( );
try {
if ( args[0].trim( ).equals( "Execute without SQL" ) )
System.out.println( "" + args[1].trim( ) + "'s ID is always 0" );
else {
// Create, compose, and execute a statement.
Statement stmt = conn.createStatement( );
String query = "SELECT ID FROM test_tbl WHERE name LIKE '%";
query += args[1].trim( ) + "%'";
System.out.println( query + "
" );
System.out.println( "" + args[1].trim( ) + "'s ID is " );
ResultSet rset = stmt.executeQuery( query );
if ( rset.next( ) )
System.out.println( rset.getString(1) );
else
System.out.println( "unknown" );
// Close the ResultSet and Statement.
rset.close( );
stmt.close( );
}
}
catch ( SQLException ex ) {
System.out.println( ex );
}
// Close the Connection.
conn.close( );
}
}