It is an important feature to determine whether a DBMS is powerful and whether external stored procedures are easy to create and use.
The ASA database has long been supporting the use of C, CLR (. NET), Java and other programming languages to create stored procedures.
The following is a simple example to create a Java-based ASA stored procedure, database (asa11.0 or later). This example is very simple. Enter the Host Name and return the corresponding IP address, if it cannot be parsed, return "".
First, write a Java class with the following content:
ImportJava.net. inetaddress;
ImportJava.net. unknownhostexception;
Public
ClassSupprocutils {
Public
StaticString getipofhost (string host) {string resolvedip = "";
Try{Resolvedip = inetaddress.
Getbyname(Host). gethostaddress ();}
Catch(Unknownhostexception e ){}
ReturnResolvedip ;}
Public
Static
VoidMain (string [] ARGs) {system.
Out. Println (
Getipofhost("Www.baidu.com "));}}
Connect to the target database and execute the following SQL statement:
1. Specify the JVM location
Alter External Environment java location 'C: \ shared \ jdk1.6.0 _ 31_x86 \ bin \ java.exe '; // This specifies the JVM location. 2. install Java classinstall Java new from file 'C: \ Users \ workspace \ test \ bin \ supprocutils. class ';
3. Create a stored procedure (function) Create Function getipofhost (in hostname char (128) returns varchar (128)
External name 'supprocutils. getipofhost (ljava/lang/string;) ljava/lang/string ;'
Language Java; here, we should pay attention to the parameter type and the Duty Type returned. You can use javap-C <class> to obtain the prototype description.
4. Example query:
Select getipofhost ('xxx .xxx.com '); Return: 100.172.102.173. In general, it is very simple. As for the creation of the C Stored Procedure of ASA, the steps are a little complicated and it may take a little time to write the code. However, the C stored procedure is the most efficient, because its execution does not require a separate JVM or CLR runtime environment.