Recently asked to develop when the data table changes when the need to call the Web interface, the Internet to find a number of articles to look at it is not very good, but also according to other people's ideas to achieve the next, the feeling is not ideal, and finally the use of urlconnection implementation of the call. Take a look at the code and test it yourself. Can be modified according to their own needs.
# #一, Triggers introduction
The definition of a trigger is that when a condition is established, the statements defined in the trigger are automatically executed. Therefore, the trigger does not need to be called artificially, nor can it be called. Then, the trigger's trigger condition is actually set when you define it. It is necessary to explain that triggers can be divided into statement-level triggers and row-level triggers. The detailed introduction can refer to the information on the Internet, simply said that the statement-level triggers can be triggered before or after some statements are executed. A row-level trigger is triggered once when the row data in the triggered table is defined.
1. First create the Java sources in Oracle
Create or replace and compile Java source named Jym as
Import Java.io.BufferedReader;
Import Java.io.InputStreamReader;
Import Java.net.URL;
Import java.net.URLConnection;
public class Jym {
public static void Sendget (String url,string title) {
String result = "";
BufferedReader in = null;
try{
String urlname = url+ "? title=" +title;
URL realurl = new URL (urlname);
URLConnection conn = Realurl.openconnection ();
Conn.setrequestproperty ("Accept", "*/*");
Conn.setrequestproperty ("Connection", "keep-alive");
Conn.connect ();
in= New BufferedReader (New InputStreamReader (Conn.getinputstream ()));
String Line;
while (line = In.readline ())!=null) {
Result + = "/n" +line;
}
}catch (Exception e) {
SYSTEM.OUT.PRINTLN ("Send GET Request Exception" +e);
E.printstacktrace ();
}
finally{
try{
if (in!=null) {
In.close ();
}
}catch (Exception e) {
E.printstacktrace ();
}
}
}
public static void Say (String ip,string title) throws Exception {
Jym.sendget (Ip,title);
}
}
2. Create a stored procedure
?
Create or Replace procedure socket (IP varchar2,title varchar2)
As language Java name
' Jym.say (java.lang.string,java.lang.string) ';
3. Create a Trigger
?
Create or Replace Trigger Instermessagenotionafter
After insert on message_notion
For each row
Begin
Socket (' http://192.168.90.132:8080/spring/ydbg/meeting/meetingpaln/related/110928171642707 ',: new.title);
End Instermessagenotionafter;
After the code is written, you can test the stored procedure first.
SQL code
Socket (' http://192.168.90.132:8080/spring/ydbg/meeting/meetingpaln/related/110928171642707 ',: new.title);
To be able to see the error message in the console, run the following 3 words first
SQL code
1. Set serveroutput on;
2. Set serveroutput on size 5000;
3. Call Dbms_java.set_output (5000);
If you are running a stored procedure and you are prompted to copy permissions to the user, follow the prompts to assign permissions under SYSDBA, such as:
SQL code
exec dbms_java.grant_permission (' Zhym ', ' SYS:java.net.SocketPermission ', ' 192.168.9.12:18002 ', ' connect,resolve ')
exec dbms_java.grant_permission (' Zhym ', ' SYS:java.net.SocketPermission ', ' 127.0.0.1:1521 ', ' connect,resolve ')
The statement after exec will be printed in your error prompt, as long as the front plus exec.
Oracle Triggers call Web interface