--sunfruit
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);