JAVA+ArcEngine开发(二):java arcengine连接sde示例代码

     1)首先建立一个ArcGis Engine Project:EngineProject

     2)在工程文件上新建一个类DataImport

读取sde dataset
import  java.io.IOException;
import  javax.swing.JFrame;
import  com.esri.arcgis.system.AoInitialize;
import  com.esri.arcgis.system.EngineInitializer;
import  com.esri.arcgis.datasourcesGDB.SdeWorkspaceFactory;
import  com.esri.arcgis.geodatabase. * ;
import  com.esri.arcgis.system. * ;


public   class  DataImport {
    
    
public   static   void  main(String[] args) 
    {
        getSDETable();
    }
    
    
public   static   void  getSDETable() {
        
try  {
        
            initializeArcGISLicenses();
            
            
            SdeWorkspaceFactory sdeFact 
=   new  SdeWorkspaceFactory();

            
//  Create a PropertySet object that will contain all of the
            
//  SDE connection parameters
            PropertySet propSet  =   new  PropertySet();

            
//  Populate the property set with the connection parameters
            propSet.setProperty( " SERVER " " 192.168.2.24 " );
            propSet.setProperty(
" INSTANCE " " 5151 " );
            propSet.setProperty(
" DATABASE " " testsde " );
            propSet.setProperty(
" USER " " sde " );
            propSet.setProperty(
" PASSWORD " " wt " );
            propSet.setProperty(
" VERSION " " sde.DEFAULT " );

            
//  Open the ArcSDE workspace using the connection PropertySet
            Workspace ws  =   new  Workspace(sdeFact.open(propSet,  0 ));

            
//  Get the collection of dataset names in the database and display their names
            IEnumDatasetName dsNames  =  ws
                    .getDatasetNames(esriDatasetType.esriDTAny);

            IDatasetName name 
=  dsNames.next();
            
while  (name  !=   null ) {
                System.out.println(name.getName());
                name 
=  dsNames.next();
            }
        } 
catch  (IOException e) {
            e.printStackTrace();
        }
    }
    
    
static   void  initializeArcGISLicenses() {
        
try  {
            EngineInitializer.initializeEngine();
            com.esri.arcgis.system.AoInitialize ao 
=   new  com.esri.arcgis.system.AoInitialize();
            
if  (ao.isProductCodeAvailable(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeEngine)  ==  com.esri.arcgis.system.esriLicenseStatus.esriLicenseAvailable)
                ao.initialize(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeEngine);
        } 
catch  (Exception e) {
            e.printStackTrace();
        }
    }
}

    3)在DataImport上右键,run as java application,运行这个类

    4)在console界面下就可以看见数据库服务器sde下的所有dataset名称

 

 

备注:initializeArcGISLicenses() 用于初始化engine的licence,如果不加的话,会提示错误:Could not load native libraries. ArcGIS/bin should be added to the system PATH environment variable.

你可能感兴趣的:(ArcEngine)