|
This is a guide to set and run Oracle. It assumes the following:
- ORACLE_HOME = E:\Oracle\Ora81
- JAVA_HOME = D:\Program Files\jdk1.3.1_01
- DEVELOPER_HOME = D:\Program Files\orawin95
- DEMO_PLSQL_HOME = C:\PLSQL
- DEMO_DEVELOPER_HOME = C:\DEVELOPER
Download the Demo sample,
extract it and test it.
The installation media should include a file called "setup.exe" which
takes launches the Oracle Universal Installer:
- Summary
Click on "Install".
- Oracle - Post-Installation:
After the installation, you may need to do the following.
- Exit from the installation.
- Shutdown Oracle: Start -> Programs -> Oracle - OraHome81 -> Database Administration -> Stop Database
- Oracle - Preparing PL/SQL:
The following scripts will build necessary data and functions for the sample test.
- Create "start.sql" under "c:\plsql":
--
-- DELETE
--
DELETE FROM log;
--
-- DROP
--
DROP TABLE log;
--
-- CREATE
--
CREATE TABLE log
(
timestamp DATE NOT NULL,
host VARCHAR2(25) NOT NULL,
application VARCHAR2(25) NOT NULL,
id INT NOT NULL,
message VARCHAR2(25) NOT NULL
);
--
-- DESCRIBE
--
DESCRIBE log;
--
-- PL/SQL
--
@triggers;
@functions;
@procedures;
--
-- INSERT through procedure
--
EXEC log_test_insert;
--
-- UPDATE through procedure
--
EXEC log_test_update('2');
--
-- SELECT
--
SELECT log.* FROM scott.log;
- Create "procedures.sql" under "c:\plsql":
--
-- log_test_insert
--
CREATE OR REPLACE PROCEDURE log_test_insert IS
current_timestamp DATE;
current_host VARCHAR2(25);
current_application VARCHAR2(25);
current_id NUMBER;
current_message VARCHAR2(25);
counter NUMBER;
BEGIN
FOR counter IN 1..10 LOOP
current_timestamp := get_sysdate();
current_host := 'localhost';
current_application := get_global_name();
current_id := counter;
current_message := 'Hello World';
INSERT INTO log (timestamp, host, application, id, message)
VALUES
(
current_timestamp, current_host, current_application, current_id, current_message
);
END LOOP;
END;
/
SHOW ERRORS;
--
-- log_test_update
--
CREATE OR REPLACE PROCEDURE log_test_update
(
modula_value NUMBER
)
IS
CURSOR log_id_cursor IS
SELECT log.id FROM log;
current_id NUMBER;
BEGIN
OPEN log_id_cursor;
LOOP
FETCH log_id_cursor INTO current_id;
EXIT WHEN log_id_cursor%NOTFOUND;
IF MOD(current_id, modula_value) = 0 THEN
UPDATE scott.log
SET log.message='Hello World Hello World'
WHERE log.id=current_id;
END IF;
END LOOP;
CLOSE log_id_cursor;
END;
/
SHOW ERRORS;
In SQL*Plus, click on File->Open and choose "c:\plsql\start.sql".
Press Enter. The purpose of this is to change the current directory
to "c:\plsql" so the PL/SQL scripts can be called.
@start.sql
The output from SQL*Plus may look like this:
SQL> @start.sql
10 rows deleted.
Table dropped.
Table created.
Name Null? Type
----------------------------------------- -------- ----------------------------
TIMESTAMP NOT NULL DATE
HOST NOT NULL VARCHAR2(25)
APPLICATION NOT NULL VARCHAR2(25)
ID NOT NULL NUMBER(38)
MESSAGE NOT NULL VARCHAR2(25)
Trigger created.
No errors.
Function created.
No errors.
Function created.
No errors.
Procedure created.
No errors.
Procedure created.
No errors.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
TIMESTAMP HOST APPLICATION ID
--------- ------------------------- ------------------------- ----------
MESSAGE
-------------------------
28-NOV-01 localhost ORCL.WORLD 1
Hello World
28-NOV-01 localhost ORCL.WORLD 2
Hello World Hello World
28-NOV-01 localhost ORCL.WORLD 3
Hello World
TIMESTAMP HOST APPLICATION ID
--------- ------------------------- ------------------------- ----------
MESSAGE
-------------------------
28-NOV-01 localhost ORCL.WORLD 4
Hello World Hello World
28-NOV-01 localhost ORCL.WORLD 5
Hello World
28-NOV-01 localhost ORCL.WORLD 6
Hello World Hello World
TIMESTAMP HOST APPLICATION ID
--------- ------------------------- ------------------------- ----------
MESSAGE
-------------------------
28-NOV-01 localhost ORCL.WORLD 7
Hello World
28-NOV-01 localhost ORCL.WORLD 8
Hello World Hello World
28-NOV-01 localhost ORCL.WORLD 9
Hello World
TIMESTAMP HOST APPLICATION ID
--------- ------------------------- ------------------------- ----------
MESSAGE
-------------------------
28-NOV-01 localhost ORCL.WORLD 10
Hello World Hello World
10 rows selected.
SQL>
The purpose of this JDBC Sample is to demonstrate how the Java Realtime
Application:
- Control requests from a Graphical User Interface.
- Connect to a database (Using an Oracle JDBC driver).
- Disconnect from the database.
- Redirect the system message from the standard output.
- Refresh system message on the Graphical User Interface periodically.
The following diagram shows:
- how the interfaces communicate with each other
through a common System Object.
- how the SystemObject encapsulates the interfaces.
--------------------------------------------------------------------------
| |
| SystemObject |
| / | \ |
| / | \ |
| / | \ |
| / | \ |
| -------------------------- ------------------- --------------------- |
| | | | | | | |
| | GraphicalUserInterface | | SystemInterface | | DatabaseInterface | |
| | | | | | | |
| | - Handles database | | - Real-time | | - Connect | |
| | requests from user | | processing | | - Query | |
| | | | | | | |
| | | | e.g. | | - Disconnect | |
| | | | Auto-refresh | | | |
| | | | on GUI messages | | | |
| | | | | | | |
| -------------------------- ------------------- --------------------- |
| |
--------------------------------------------------------------------------
- Java - Create JDBC Sources:
- Create "SystemInterface.java" under the directory
"c:\jdbc":
import java.lang.*;
import SystemObject;
import java.io.*;
public class SystemInterface extends java.lang.Thread
{
private static final int SLEEP_INTERVAL = 1000;
private SystemObject systemObject;
private boolean processFlag;
private java.io.ByteArrayOutputStream byteArrayOutputStream;
public SystemInterface
(
SystemObject systemObjectValue
)
{
super();
this.setProcessFlag(false);
this.setSystemObject(systemObjectValue);
this.setByteArrayOutputStream();
java.lang.System.setOut
(
new java.io.PrintStream
(
(java.io.OutputStream)
this.getByteArrayOutputStream(),
true
)
);
java.lang.System.setErr
(
new java.io.PrintStream
(
(java.io.OutputStream)
this.getByteArrayOutputStream(),
true
)
);
return;
}
public void run
(
)
{
for (;;)
{
try
{
if (java.lang.Thread.currentThread() == this)
{
this.broadcast();
if (this.getProcessFlag() == true)
{
this.startProcess();
this.setProcessFlag(false);
continue;
}
this.sleep(this.SLEEP_INTERVAL);
}
}
catch
(
java.lang.Exception exceptionValue
)
{
java.lang.System.err.println(exceptionValue.toString());
break;
}
java.lang.Thread.yield();
}
return;
}
public void startProcess
(
)
{
if (this.getSystemObject().getDatabaseInterface().connect() == false)
{
return;
}
this.getSystemObject().getDatabaseInterface().query
(
"select log.* from scott.log"
);
this.getSystemObject().getDatabaseInterface().disconnect();
return;
}
public void broadcast
(
)
{
this.getSystemObject().getGraphicalUserInterface().
getOutputTextArea().setText
(
this.getSystemObject().getSystemInterface().
getByteArrayOutputStream().toString()
);
this.getSystemObject().getGraphicalUserInterface().
getOutputTextArea().select
(
this.getSystemObject().getGraphicalUserInterface().
getOutputTextArea().getText().length(),
this.getSystemObject().getGraphicalUserInterface().
getOutputTextArea().getText().length()
);
return;
}
public void setSystemObject
(
SystemObject systemObjectValue
)
{
this.systemObject = systemObjectValue;
return;
}
public SystemObject getSystemObject
(
)
{
return this.systemObject;
}
public void setProcessFlag
(
boolean flagValue
)
{
this.processFlag = flagValue;
return;
}
public boolean getProcessFlag
(
)
{
return this.processFlag;
}
public void setByteArrayOutputStream
(
)
{
this.byteArrayOutputStream =
new java.io.ByteArrayOutputStream();
return;
}
public ByteArrayOutputStream getByteArrayOutputStream
(
)
{
return this.byteArrayOutputStream;
}
}
- Create "GraphicalUserInterface.java" under the directory
"c:\jdbc":
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import SystemObject;
public class GraphicalUserInterface extends java.awt.Frame
implements java.awt.event.ItemListener,
java.awt.event.ActionListener
{
private static final int DIMENSION_WIDTH = 640;
private static final int DIMENSION_HEIGHT = 480;
private static final int TEXTAREA_ROW = 20;
private static final int TEXTAREA_COLUMN = 50;
private SystemObject systemObject;
private java.awt.GridBagLayout gridBagLayout;
private java.awt.Choice inputChoice;
private java.awt.Button inputButton;
private java.awt.TextArea outputTextArea;
public GraphicalUserInterface
(
SystemObject systemObjectValue
)
{
super();
this.setSystemObject(systemObjectValue);
this.setGridBagLayout();
// Event
super.enableEvents(java.awt.AWTEvent.WINDOW_EVENT_MASK);
// Size
super.setSize
(
this.DIMENSION_WIDTH,
this.DIMENSION_HEIGHT
);
// Title
super.setTitle
(
this.getClass().getName()
);
// Layout
super.setLayout(this.getGridBagLayout());
// Components
this.setInputChoice();
this.setInputButton();
this.setOutputTextArea();
return;
}
/*
// Events
*/
protected void processWindowEvent
(
java.awt.event.WindowEvent windowEventValue
)
{
super.processWindowEvent(windowEventValue);
if (windowEventValue.getID() ==
java.awt.event.WindowEvent.WINDOW_CLOSING)
{
super.setVisible(false);
super.dispose();
java.lang.System.exit(0);
}
return;
}
public void itemStateChanged
(
java.awt.event.ItemEvent itemEventValue
)
{
java.awt.Choice choice;
choice = (java.awt.Choice) itemEventValue.getItemSelectable();
if (choice.getSelectedIndex() == 0)
{
return;
}
return;
}
public void actionPerformed
(
java.awt.event.ActionEvent actionEventValue
)
{
if (this.getInputChoice().getSelectedIndex() == 0)
{
this.getSystemObject().getSystemInterface().setProcessFlag(true);
return;
}
return;
}
/*
// Methods
*/
public void addComponent
(
java.awt.Component componentValue,
int rowValue,
int columnValue,
int widthValue,
int heightValue,
int weightxValue, // can grow wider
int weightyValue, // can grow taller
int fillValue
)
{
java.awt.GridBagConstraints gridBagConstraints =
new java.awt.GridBagConstraints();
gridBagConstraints.gridx = columnValue;
gridBagConstraints.gridy = rowValue;
gridBagConstraints.gridwidth = widthValue;
gridBagConstraints.gridheight = heightValue;
gridBagConstraints.weightx = weightxValue;
gridBagConstraints.weighty = weightyValue;
gridBagConstraints.fill = fillValue;
this.gridBagLayout.setConstraints
(
componentValue,
gridBagConstraints
);
super.add(componentValue);
return;
}
public void start
(
)
{
super.setVisible(true);
}
public void setSystemObject
(
SystemObject systemObjectValue
)
{
this.systemObject = systemObjectValue;
return;
}
/*
// Attribute Methods
*/
public SystemObject getSystemObject
(
)
{
return this.systemObject;
}
public void setGridBagLayout
(
)
{
this.gridBagLayout = new java.awt.GridBagLayout();
return;
}
public java.awt.GridBagLayout getGridBagLayout
(
)
{
return this.gridBagLayout;
}
public void setOutputTextArea
(
)
{
this.outputTextArea = new java.awt.TextArea();
this.outputTextArea.setRows(this.TEXTAREA_ROW);
this.outputTextArea.setColumns(this.TEXTAREA_COLUMN);
this.outputTextArea.setEditable(false);
this.outputTextArea.setEnabled(true);
this.outputTextArea.setText(null);
this.outputTextArea.setVisible(true);
this.addComponent(this.outputTextArea, 2, 1,
1, 1, 0, 0, java.awt.GridBagConstraints.NONE);
return;
}
public java.awt.TextArea getOutputTextArea
(
)
{
return this.outputTextArea;
}
public void setInputChoice
(
)
{
this.inputChoice = new java.awt.Choice();
this.inputChoice.addItemListener(this);
this.inputChoice.add("Oracle");
this.addComponent(this.inputChoice, 1, 1,
1, 1, 0, 0,
java.awt.GridBagConstraints.HORIZONTAL);
return;
}
public java.awt.Choice getInputChoice
(
)
{
return this.inputChoice;
}
public void setInputButton
(
)
{
this.inputButton = new java.awt.Button();
this.inputButton.addActionListener(this);
this.inputButton.setLabel("OK");
this.inputButton.setVisible(true);
this.addComponent(this.inputButton, 1, 2,
1, 1, 0, 0, java.awt.GridBagConstraints.NONE);
return;
}
public java.awt.Button getInputButton
(
)
{
return this.inputButton;
}
}
- Create "DatabaseInterface.java" under the directory
"c:\jdbc":
import java.lang.*;
import java.sql.*;
import java.io.*;
import SystemObject;
public class DatabaseInterface extends java.lang.Object
{
private SystemObject systemObject;
private java.sql.Connection connection;
private java.sql.Statement statement;
private java.sql.ResultSet resultSet;
public DatabaseInterface
(
SystemObject systemObjectValue
)
{
super();
this.setSystemObject(systemObjectValue);
return;
}
/*
// Methods
*/
public boolean connect
(
)
{
boolean flag;
flag = true;
try
{
java.sql.DriverManager.registerDriver
(
new oracle.jdbc.driver.OracleDriver()
);
this.setConnection
(
java.sql.DriverManager.getConnection
(
"jdbc:oracle:oci8:@orcl.world",
"scott",
"tiger"
)
);
java.sql.DriverManager.setLogWriter
(
new java.io.PrintWriter(java.lang.System.out, true)
);
}
catch
(
java.lang.Exception exceptionValue
)
{
java.lang.System.err.println(exceptionValue.toString());
flag = false;
}
return flag;
}
public void query
(
java.lang.String queryValue
)
{
int index;
try
{
this.setStatement
(
this.getConnection().createStatement()
);
this.setResultSet
(
this.getStatement().executeQuery
(
queryValue
)
);
while (this.getResultSet().next() == true)
{
index = 1;
while (index <= this.getResultSet().getMetaData().getColumnCount())
{
java.lang.System.out.println(this.getResultSet().getString(index));
index++;
}
}
this.getResultSet().close();
}
catch
(
java.lang.Exception exceptionValue
)
{
java.lang.System.err.println(exceptionValue.toString());
return;
}
return;
}
public void disconnect
(
)
{
try
{
this.getConnection().close();
}
catch
(
java.lang.Exception exceptionValue
)
{
java.lang.System.err.println(exceptionValue.toString());
return;
}
return;
}
/*
// Attribute Method
*/
public void setSystemObject
(
SystemObject systemObjectValue
)
{
this.systemObject = systemObjectValue;
return;
}
public SystemObject getSystemObject
(
)
{
return this.systemObject;
}
public void setConnection
(
java.sql.Connection connectionValue
)
{
this.connection = connectionValue;
return;
}
public java.sql.Connection getConnection
(
)
{
return this.connection;
}
public void setStatement
(
java.sql.Statement statementValue
)
{
this.statement = statementValue;
return;
}
public java.sql.Statement getStatement
(
)
{
return this.statement;
}
public void setResultSet
(
java.sql.ResultSet resultSetValue
)
{
this.resultSet = resultSetValue;
return;
}
public java.sql.ResultSet getResultSet
(
)
{
return this.resultSet;
}
}
Make sure that the Oracle server has already started
and the PL/SQL sample scripts were executed.
NOTE: The following Developer setup deals with
the Window Registry file. So it may damage the Windows 98 Operating
System if the settings are incorrect.
- Developer - First Installation:
- Run "setup.exe" from installation media.
- Oracle Developer Installation Options:
Development Installation -> Cancel
- Software Asset Manager:
Highlight all the available products and hit "Install"
- Error Information:
"GUI60.vrf(56): FILE_NOT_FOUND while translating NLS_LANG from $oracle"
OK and Exit.
This error message should not appear in the next
installation attempt. The second installation attempt on
Developer 6 should treat "d:\progra~1\orawin95" as
the new Oracle Home by default rather than "e:\oracle\ora81".
- Developer - Second Installation:
- Repeat the steps of the First Installation. The error information
prompt should not appear in the Second Installation.
- INTERSOLV DataDirect Driver Selection: None
- When installation is completed, it will prompt the user.
- Backup "d:\progra~1\orawin95\net80\admin\tnsnames.ora"
to "d:\progra~1\orawin95\net80\admin\tnsnames.ora.old"
- Developer - Form Builder:
- Object Navigator (Tools -> Object Navigator)
- Adding an OK Button
Layout Editor (Tools -> Layout Editor)
- Select the "Button" icon on the left of the Layout Editor.
- Click it within the frame border and a button will appear.
- Double click on the button and a "Property Palette" window will appear
- On the Property Palette, go to Functional -> Label and change it
to "Insert".
- With the button still selected, use the right mouse button to click
on the button and select "PL/SQL Editor".
- Select "WHEN-BUTTON-PRESSED" for its Trigger.
- In the "PL/SQL Editor" enter the following and then click
on the "Compile" button.
begin
insert into log(timestamp, host, application, id, message)
values(:timestamp, :host, :application, :id, :message);
end;
- On SQL*Plus, enter the following query.
select * from log;
The new entry should be listed.
- Developer - Form Compiler:
- Developer - Form Runtime:
- Developer - Graphics Builder:
- Developer - Report Builder:
- "Build a new report manually"
File -> New -> Report
- Developer - Report Compiler:
- Developer - Report Runtime:
|