Create an external Stored Procedure for Sybase ASA (Java example)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.