ASE12.5 Database Inside Java Development Guide

zhaozj2021-02-16  49

ASE12.5 Database Inside Java Development Guide

Author: Weng Yan

Time: April 2004 platform

Windows 2000 Server

ASE 12.5 Developer EDTION for NT

statement

Welcome to reprint, please keep this admission information

ENHYDRABOY@yahoo.com.cn

Used Oracle 8i, knowing Oracle 8i, you can embed Java objects in the database through the loadjava command. This allows the PL / SQL program to call these Java objects. The advantage of this technology is:

1 Extend the function of the PL / SQL program, we know that PL / SQL is extended to the SQL command, which can perform logical operation, but with the support of Java language, it will be more

2 You can provide us with a new type of data type. Now RDBMS supports custom types, and object types. However, the customized type is only related to a database. When migration between different databases, these data types obviously cannot migrate (you must implement this part in the new database, maybe you change the code) Will be unpredictable). This makes us have to worry about the use of object data types, and even give up. Java can help us completely cancer.

Below, I simply talk about how it is applied in Sybase 12.5.

1 First, you must first allow the database to support Java's characteristics. SP_CONFIGURE "Enable Java", 1

1> sp_configure "enable java", 1

2> Go

Parameter Name Default Memory Used Config Value

Run Value Unit Type

------------------------------------ - ----------------

----------------------------------------

Enable java 0 0 1

0 Switch Static

(1 row affed)

Configuration Option Changed. Since the option is static, Adaptive Server MUST

Be rebooted in Order for the change to take.

Changing the value of 'Enable Java' to '1' Increases The Amount of Memory ASE

Uses by 6482 k.

(return status = 0)

2 Restart the Sybase database. NT below, you can restart by the Control Panel -> Management Tools -> service.

3 Good, below, let's simply develop a Java program, then look at how the Sybase's T-SQL is called.

Java program

Package sam;

Public class helloworld {public string hello () {return "helloworld";

} 4 Compile and package this Java program. Java Jar CF0 Sam.jar SAM / *. Class 5 Install the Java package to the database, with the instaxava program provided by Sybase, this program is installed together with Sybase installation. To explain, the NT and UNIX command names are different. Under UNIX is Installjava, Windows NT is Instaxva. Instjava -f "e: / working directory /sybase/java/sam.jar" -new -j-s sam -u sa -p -d northwind

6 Adding a Hello method in sybase transaction-sql

1> SELECT (New Sam.helloWorld ()) >> Hello () 2> Go

-------------------------------------------------- HelloWorld We can see that Sybase basically uses Java syntax, so Java programmers should be easy to use. 7. Below, I will talk about the development of the second feature (Java object type). Package sam;

Public class address information java.io.serializable {private string varcity; private string varzip; private string varcha

Public Address (String Mcity, String McOUNTRY, String Mzip, String MHOME) {varcity = mcity; varcountry = mcountry; varzip = mzip; varHome = MHOME;

Public String City () {Return Varcity;

Public String Country () {Return Varcountry;

Public string homeaddress () {return varhome;}

Public string zip () {returnve varzip;}

Public void modifyaddress (string mcity, string mcountry, string mzip, string mhome {varcity = mcity; varcountry = mcountry; varzip = mzip; varHome = MHOME;

} 8 compiled, packaged, and installed. Now we can use this Java object type directly. Built a table, the database field type is a Java class. Note: You can use the Java class with the database field type, you must implement the Java.io.Serializable interface. 1> Create Table Emps (2> Empno Int, 3> Name VARCHAR (30), 4> Addr Sam.address DEFAULT New Sam.address 5> ('NOT KNOWN', ',', ') 6>) 7> GO 1> ALTER TABLE EMPS ADD CONSTRAINT PK_EMPS PRIMARY Key (Empno) 2> GO operation and use the Java type field. 1> INSERT INTO EMPS (Empno, Name) Values ​​(1, 'Tom') 2> Go (1 Row Affected) 1> Insert Into Emps Values ​​(2, 'Bob ", 2> New Sam.address (' Shanghai ', 'China', '200132', '1169, nanjin road')) 3> Go (1 row affected) 1> Begin 2> Declare @a sam.address 3> SELECT @ a = addr from Emps where Empno = 2 4> Select @a >> country (), @ a >> city (), @ a >> homeaddress (), @ a >> zip () 5> end 6> Go

-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- China Shanghai 1169, Nanjin Road 200132

(1 Row Affected) Through the simple example, it is hoped that you can help everyone's actual system development.

转载请注明原文地址:https://www.9cbs.com/read-23626.html

New Post(0)