// Import the following packages to use JDBC.
import java.sql.*;
import java.io.*;
import oracle.sql.*;
import oracle.jdbc.*;
import oracle.jdbc.pool.OracleDataSource;
class Select {
public static void main( String args[ ] ) throws SQLException {
String user = "C##user.id";
String password = "password";
String database = "65.52.222.73:1521/cdb1";
// 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( );
// Create a Statement
Statement stmt = conn.createStatement( );
// Select first_name, last_name, and email columns from the employee_tbl2 table
String query = "SELECT first_name, last_name, email FROM employee_tbl2";
query += " WHERE first_name LIKE '%" + args[0].trim( ) + "%'";
System.out.println( "<font color='#3366CC'><h4>" + query + "</h4></font>" );
ResultSet rset = stmt.executeQuery( query );
// Iterate through the result and print the employee names.
while ( rset.next( ) )
System.out.println (
rset.getString( 1 ) + " " + rset.getString( 2 ) + ": " +
rset.getString( 3 ) );
// Close the ResultSet, Statement, and Connection.
rset.close( );
stmt.close( );
conn.close( );
}
}
|