Oracle Spatial新驅動的添加記錄執行個體

來源:互聯網
上載者:User

Oracle的空間資料庫的操作驅動更新了,新的驅動適用於Oracle8.0或以上,新驅動在對資料庫的操作上面和原有的驅動差別比較大,不過有一點:使用變得簡單了
建立空間資料庫和建立空間索引的步驟就略過了,那些網上有很多例子,而且實現方式上面也沒有變化,下面列出添加一條空間資料庫記錄的代碼:

import java.sql.*;
import oracle.sql.*;
import oracle.spatial.geometry.JGeometry;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class SdoAdd {
public static void main(String[] args) {
String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@172.16.75.200:1521:starmap";
String uid = "hmbst";
String psw = "hmbst";
Connection conn = null;
PreparedStatement ps=null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(url, uid, psw);

JGeometry jGeometry=new JGeometry(41884696,14377039,0);
STRUCT obj =jGeometry.store(jGeometry,conn);
String sql =
"insert into POISDO values(seq_poi_id.nextval,?,?)";
ps = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
ps.clearParameters();
ps.setString(1, "我的家");
ps.setObject(2, obj);
// 插入點地物記錄
ps.executeUpdate();
conn.commit();
}
catch (Exception ex) {
ex.printStackTrace();
}
finally
{
if(conn!=null)
{
try {
conn.close();
}
catch (SQLException ex) {
ex.printStackTrace();
}
}
if(ps!=null)
{
try {
ps.close();
}
catch (SQLException ex) {
ex.printStackTrace();
}
}

}
}
}

表POISDO的結構如下

create table poi (
id INTEGER,
gname VARCHAR2(256),
gshape MDSYS.SDO_GEOMETRY);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.