Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1332802
  • 博文数量: 185
  • 博客积分: 50
  • 博客等级: 民兵
  • 技术积分: 3934
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-11 13:11
个人简介

iihero@ChinaUnix, ehero.[iihero] 数据库技术的痴迷爱好者. 您可以通过iihero AT qq.com联系到我 以下是我的三本图书: Sybase ASE in Action, Oracle Spatial及OCI高级编程, Java2网络协议内幕

文章分类

全部博文(185)

文章存档

2014年(4)

2013年(181)

分类: C/C++

2013-07-17 13:29:21

1.使用oci或者occi,在安装oracle后可以在oraclehome/md/demo/examples目录下参考其C++实现,
该方法效率最高,但实现比较复杂;

2.使用Oracle提供的OO4O,是com,在vb6代码如下:
'***************************************************************
'Gisc Lab, Nanjing Normal University
'
'Purpose: This Demo Shows how to read spatial data from Oracle
'
'Input: User ID='Scott', Password='Tiger', Data Source='Apollo',
'       SQL='select * from interstates where rownum<2'
'
'Output: xmlDocument or xmlReader
'
'Author: Charlie Chen
'
'Data: 7-28-2004
'***************************************************************
 
 Dim OraSession As OraSessionClass
 Dim OraDatabase As OraDatabase
 Dim interstates As OraDynaset
 Dim geom As OraObject
 Dim coords As OraCollection
 

Private Sub Command1_Click()
    Set OraSession = New OraSessionClass
    
    
    Set OraDatabase = OraSession.OpenDatabase("apollo", "scott/tiger", 0&)
    
    Set interstates = OraDatabase.CreateDynaset("select * from interstates where rownum<2", 0&)
    
    Set geom = interstates.Fields("GEOM").Value
    
    Set coords = geom.SDO_ORDINATES

    For i = 1 To coords.Size
        Debug.Print coords.Item(i)
    Next i
End Sub

程序可读性和维护性较好,需要添加对oip9.tlb的引用

3.使用ODP.NET(Oracle公司提供的在.net平台上的数据访问组件),在.NET环境下可以直接转换为xml坐标字符串,但效率太低;

4.使用JDBC或者SDO API,无论从哪方面来讲都比较理想。

补充.net平台上的实现,代码如下:

    private XmlDocument GetSpatialData(string connectionString, string SQL)
        {
            OracleConnection con = new OracleConnection(connectionString);

            try
            {
                con.Open();

                OracleCommand cmd = new OracleCommand(SQL, con);
                cmd.XmlCommandType =  OracleXmlCommandType.Query;
                cmd.BindByName = true;
                int rows = cmd.ExecuteNonQuery();

                XmlReader xmlReader = cmd.ExecuteXmlReader();

                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.PreserveWhitespace = true;
                xmlDocument.Load(xmlReader);

                return xmlDocument;
            }
            catch(Exception e)
            {
                throw e;
            }
            finally
            {
                if (con.State == System.Data.ConnectionState.Open) con.Close();
                con.Dispose();
            }
        }

    调用:
    string constr = "User Id=scott;Password=tiger;Data Source=apollo";
        string sql = "select * from interstates where rownum<2";

        XmlDocument xmlDocument = GetSpatialData(constr, sql);

        Console.WriteLine((xmlDocument != null) ? xmlDocument.InnerXml : "fail to read");


阅读(2438) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~