This slide shows how to send the user input including radio buttons to a server for processing.
If you select a radio button below and click the “Submit” button, the browser will call the following scripts:
⇒ ⇒ ⇒ ⇒
and list the corresponding cities and descriptions based on the selected sales.
The following JDBC script accesses the database and retrieves the cities and descriptions.
~/public_html/cgi-bin/jdbc/Radio.java
/*******************************************************************
This program shows how to list the cities and
descriptions in the stores and productions tables
based on the sales.
To use this program, you need to create the following
three tables by using the following commands:
SQL> CREATE TABLE stores (
2 store_key INTEGER PRIMARY KEY,
3 city VARCHAR(32) NOT NULL,
4 region VARCHAR(16) NOT NULL );
SQL> CREATE TABLE products (
2 product_key INTEGER PRIMARY KEY,
3 description VARCHAR(32) NOT NULL,
4 brand VARCHAR(32) NOT NULL );
SQL> CREATE TABLE sales_fact (
2 store_key INTEGER,
3 product_key INTEGER,
4 sales NUMBER(5,2) NOT NULL,
5 cost NUMBER(5,2) NOT NULL,
6 profit NUMBER(5,2) NOT NULL,
7 PRIMARY KEY ( store_key, product_key ),
8 FOREIGN KEY ( store_key ) REFERENCES stores( store_key ) ON DELETE CASCADE,
9 FOREIGN KEY ( product_key ) REFERENCES products( product_key ) ON DELETE CASCADE );
*******************************************************************/
// Import the following packages to use JDBC.
import java.sql.*;
import java.io.*;
import oracle.jdbc.*;
import oracle.jdbc.pool.OracleDataSource;
class Radio {
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 {
// Create, compose, and execute a statement.
Statement stmt = conn.createStatement( );
String query = "select city, description from sales_fact f, stores s, products p ";
query += "where sales >= " + args[0].trim( ) + " and sales < " + args[1].trim( );
query += " and f.store_key=s.store_key and f.product_key=p.product_key";
System.out.println( query + "<b>" );
ResultSet rset = stmt.executeQuery( query );
// Iterate through the result and print the data.
while ( rset.next( ) )
System.out.print( rset.getString(1) + ": " + rset.getString(2) );
// Close the ResultSet and Statement.
rset.close( );
stmt.close( );
}
catch ( SQLException ex ) {
System.out.println( ex );
}
// Close the Connection.
conn.close( );
}
}