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