当前位置: 代码迷 >> Web前端 >> java arcsde 联接oracle
  详细解决方案

java arcsde 联接oracle

热度:777   发布时间:2012-10-10 13:58:11.0
java arcsde 连接oracle
写道
SDEDBManager .java
package com.digitalchina.arcgis.common;

import java.util.Calendar;

import com.esri.sde.sdk.client.SeConnection;
import com.esri.sde.sdk.client.SeCoordinateReference;
import com.esri.sde.sdk.client.SeDelete;
import com.esri.sde.sdk.client.SeException;
import com.esri.sde.sdk.client.SeInsert;
import com.esri.sde.sdk.client.SeLayer;
import com.esri.sde.sdk.client.SeRow;
import com.esri.sde.sdk.client.SeShape;

public class SDEDBManager {
	private static String server = "192.168.1.200";
	private static String instance ="5151";
	private static String database = "ORCL";
	private static String username = "sde";
	private static String password = "sde";

	public  static SeConnection getConn() {
		SeConnection conn = null;
		if (conn == null) {
			try {
				conn = new SeConnection(server, instance, database, username,password);
			} catch (SeException ex) {
				ex.printStackTrace();
			}
		}
		return conn;
	}
	
	public static void main(String args[]){
	   new SDEDBManager().delete("camera");
		//new SDEDBManager().insertOnePoint();
	}
	public void  insert(){
		SeConnection conn=getConn();
		if(conn!=null){
			try{
				SeInsert insert =new SeInsert(conn);
				insert.intoTable("PT", new String[]{"SHAPE","NAME","VISITTIME","FCC","FROMTIME","TOTIME","SUBTYPES" });
				insert.setWriteMode(true);//开启buffer
				SeLayer layer=new SeLayer(conn,"PT","SHAPE");
				SeCoordinateReference cr =layer.getCoordRef();
			    for(int i=0;i<10;i++){
					SeRow row =insert.getRowToSet();
					SeShape shape=new SeShape(cr);
					String wkt="POINT("+i+" "+i+")";
					shape.generateFromText(wkt);
					row.setShape(0, shape);
					row.setNString(1, "名称"+i);
					row.setDouble(2, 20.0);
					row.setNString(3, "D31");
					row.setTime(4,Calendar.getInstance());
					row.setTime(5,Calendar.getInstance());
					row.setInteger(6, new Integer(2));
					insert.execute();
				 }	
				insert.flushBufferedWrites();
				insert.close();
			}catch(SeException e){
				e.printStackTrace();
			}finally{
				try{
					conn.close();
				}catch(SeException e){
					e.printStackTrace();
				}
			}
		}
	}
	public void delete(String tableName){
		SeConnection	conn=getConn();
		if(conn!=null){
			try{
				 SeDelete delete = new SeDelete(conn);
				 delete.fromTable(tableName, "OBJECTID>0");
			}catch(SeException e){
				e.printStackTrace();
			}finally{
				try{
					conn.close();
				}catch(SeException e){
					e.printStackTrace();
				}
			}
		}
	}
	
	public void  insertOnePoint(){
		SeConnection	conn=getConn();
		if(conn!=null){
			try{
				SeInsert insert =new SeInsert(conn);
				insert.intoTable("FIRE", new String[]{"SHAPE","NAME",  "FROMTIME","TOTIME","SUBTYPES" });
				insert.setWriteMode(true);//开启buffer
				SeLayer layer=new SeLayer(conn,"HOSPITAL","SHAPE");
				SeCoordinateReference cr =layer.getCoordRef();
				SeRow row =insert.getRowToSet();
				SeShape shape=new SeShape(cr);
				String wkt="POINT(-122.43644 37.76927)";
				shape.generateFromText(wkt);
				row.setShape(0, shape);
				row.setNString(1, "FIRE CENTER");
				row.setTime(2,Calendar.getInstance());
				row.setTime(3,Calendar.getInstance());
				row.setInteger(4, new Integer(2));
				insert.execute();
				insert.flushBufferedWrites();
				insert.close();
			}catch(SeException e){
				e.printStackTrace();
			}finally{
				try{
					conn.close();
				}catch(SeException e){
					e.printStackTrace();
				}
			}
		}
	}
	
	 

	
}

??

  相关解决方案