文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>新一代数据库amos2与java集成的配置和程序设计

新一代数据库amos2与java集成的配置和程序设计

时间:2010-06-27  来源:woods2001

上一篇文章介绍过,amos2和java的集成开发环境的配置。 这片文章详细介绍基于前一篇文章配置下的环境下进行开发的一些应该注意的地方。 1.进入javaamos开发环境 D:\amos2\amos2\bin>java JavaAMOS Stu.dmp
JavaAMOS 1>
注释:JavaAMOS 已经配置的环境变量中,数据库Stu.dmp在当前目录下,也可不在当前目录下,此时使用相对路径和绝对路径均可。 2.打开amos2图形开发界面 JavaAMOS 1> goovi();
1.391 s
JavaAMOS 1> 注释:此时会出现一个基于java程序的amos2数据库管理系统界面,该界面提供更加友好的开发环境,很多初学者更喜欢具有界面的开发环境。 3.编制java程序,生成可供amos2调用的类 下面我给出一个简单的使用学生-教师信息数据库的java类  

import callin.*;
import callout.*;

public class stu_aggregation
{
    public stu_aggregation(){}
    public void sum_age_sysfunc(CallContext cxt, Tuple tpl) throws AmosException
    {
        try
        {
            Connection theconnection=new Connection("");
            Scan scan = theconnection.execute("sum(select x from integer x,Student s where x=age(s) and Speciality(s)=" + "\"" + tpl.getStringElem(0) + "\"" + ");");
            System.out.println("专业: " + tpl.getStringElem(0) + " 的");
            System.out.println("总年龄为: " + scan.getRow().getIntElem(0));
        }
        catch(AmosException e)
        {
            throw(e);
        }
    }
    public void sum_age_user_d_func(CallContext cxt, Tuple tpl) throws AmosException
    {
        try
        {
            int sum_age = 0;
            int age_temp = 0;
            Connection theconnection=new Connection("");
            Scan scan = theconnection.execute("select name, age from integer age, charstring name, Student s where age=age(s) and name=name(s) and Speciality(s)=" + "\"" + tpl.getStringElem(0) + "\"" + ";");
            System.out.println("姓名 " + "年龄");
            while(!scan.eos())
            {
                Tuple thetpl = scan.getRow();
                System.out.printf("%-12s %d\n", thetpl.getStringElem(0), thetpl.getIntElem(1));
                age_temp = thetpl.getIntElem(1);
                sum_age += age_temp;
                scan.nextRow();
            }
            System.out.println("专业: " + tpl.getStringElem(0) + " 的");
            System.out.println("总年龄为: " + sum_age);
        }
        catch(AmosException e)
        {
            throw(e);
        }
    }
    public void avg_age(CallContext cxt, Tuple tpl) throws AmosException
    {
        try
        {
            Connection theconnection=new Connection("");
            int avg_age = 0;
            int total_age = 0;
            int count = 0;
            Scan scan = theconnection.execute("sum(select x from integer x,Student s where x=age(s) and Speciality(s)=" + "\"" + tpl.getStringElem(0) + "\"" + ");");
            total_age = scan.getRow().getIntElem(0);
            scan = theconnection.execute("count(select x from integer x,Student s where x=age(s) and Speciality(s)=" + "\"" + tpl.getStringElem(0) + "\"" + ");");
            count = scan.getRow().getIntElem(0);
            avg_age = total_age / count;
            System.out.println("专业: " + tpl.getStringElem(0) + " 的");
            System.out.println("专业人数: " + count);
            System.out.println("总年龄为: " + total_age);
            System.out.println("平均年龄为: " + avg_age);
        }
        catch(AmosException e)
        {
            throw(e);
        }
    }
    public void age(CallContext cxt, Tuple tpl) throws AmosException
    {
        try
        {
            Connection theconnection=new Connection("");
            int age;
            Scan thescan = theconnection.execute("select x from integer x, Person p where x=age(p) and name(p)="
                                                 + "\"" + tpl.getStringElem(0) + "\"" + ";");
            System.out.println("年龄: " + thescan.getRow().getIntElem(0));
        }
        catch(AmosException e)
        {
            throw(e);
        }
    }
}


4.编译该类

D:\amos2\amos2\bin>javac stu_aggregation.java

D:\amos2\amos2\bin>

5.在javaamos中使用该类

回到第一步和第二步,进入了javaamos后可以使用第三步创建的类。

使用方法是:1.创建类中提供方法的引用

 eg:create function get_age(charstring)->integer as
foreign "JAVA:stu_aggregation/age";

           2.使用该方法

JavaAMOS 3> age_sum_user("CS");
姓名        年龄
TUYOUWU      24
XIAJING      23
ZHANGLEI     28
WANGYONGGANG 24
专业: CS 的
总年龄为: 99
0.172 s

趁着刚做完实验,简单的把实验步骤和心得写出来,供参考所用,如有不够详尽的地方,可以联系本人。

                                          南京航空航天大学信息科学与技术学院

                                               09级  涂友武

                                               QQ:276362907

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载