Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Oracle Database Triggers / Java Stored Procedures
Hello,
I am very new to Oracle so do not have a lot of background here... I have Oracle 8.1.6 Personal Edition on NT 4, and am using XML tools from XDK for Java 8.1.7.1.0A.
I want to set up a Java Stored Procedure and have it fire off of a database trigger. The stored procedure will call a Java class that I load into the database.
The Java class will essentially do a "SELECT * FROM SCOTT.BLAHBLAH" and send a XML stream off to another server for processing.
The database trigger will fire after an insert or update or delete on the table SCOTT.BLAHBLAH.
The sequence of events is:
1) Someone inserts, deletes of modifies a row in SCOTT.BLAHBLAH 2) The trigger fires and calls the Java Stored Procedure 3) The stored procedure calls a static method on a Java class thatSELECTs rows from SCOTT.BLAHBLAH and sends them off to another server. My Java class/static method builds the SQL and passes the SQL string to OracleXMLQuery (conn, sql.toString ());
I include 3 "source" items at the end of this message: 1) OracleInternalXMLQuery.java - Does the SELECT and sends the result (as an XML string) offboard for processing. 2) My Oracle PL/SQL procedure - TestOracleInternalXmlQuery 3) My Oracle PL/SQL trigger - blahblah_after_update_row
I have two questions:
I am looking for resources on *how* to write database triggers. I am looking for books on the topic or on line resources...
2) The thing I am really after is a trigger / Java Stored Procedure that will just stream off the *rows that changed* from the table SCOTT.BLAHBLAH. You know, maybe I have a large number of rows and I just want to send off the rows that were affected by an update, delete or insert.
I will appreciate any thoughts on this, or pointers in the right direction.
Thank you,
Fred Burkley
import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.net.Socket; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException;
/** * */
/** */
static Connection conn = null;
static String default8iConn = "jdbc:oracle:kprb:";
static String thinConn =
"jdbc:oracle:thin:@MY_HOST_NAME:1521:MY_SID";
// static initializers
static {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace ();
}
try {
if (insideOracle8i ()) { conn = DriverManager.getConnection(default8iConn, "SCOTT",
"TIGER");
} else { conn = DriverManager.getConnection(thinConn, "SCOTT", "TIGER"); }
/** * */
StringBuffer sql = new StringBuffer ("SELECT * FROM BLAHBLAH"); OracleXMLQuery xmlQuery = new OracleXMLQuery (conn, sql.toString ());
String xmlString = xmlQuery.getXMLString (); System.out.println (xmlString);
// write to socket
try {
Socket soc = new Socket ("MY_HOST_NAME", 8005); PrintWriter out = new PrintWriter (soc.getOutputStream ()); out.print (xmlString); out.close ();
/** * */
/** * */
--Received on Sat Jul 21 2001 - 18:51:50 CDT