how to use java connecting to arcsde 10.1( base oracle 11.2g)

5668
15
12-17-2012 02:28 AM
zhangyx
New Contributor
i install oracle 11.2g, then use arcgis gp tool create arcsde geodatabase on oracle 11.2g.    how can i use java to connect to arcsde.

how can i write the fallowing code ?

SeConnection connection = null;
connection = new SeConnection(server, instance, database, user, password);
0 Kudos
15 Replies
LeoDonahue
Regular Contributor
ArcObjects Java API is still in play for connecting to your database.  You just need the undocumented correct combination of connection propertyset properties.

I assume you have the correct version of ArcObjects libraries for doing this.  It seems logical that I could not use an ArcObjects 9.3 installation to connect to a newer version of SDE.

Notice the change in SERVERINSTANCE to INSTANCE... that one threw us for a few days.  Found help in the forums.

You can adapt this to Oracle... yes?

    private static void connectToSQLServer(){

        try {

            IPropertySet propertySet = new PropertySet();
            propertySet.setProperty("SERVER", "server name");
            propertySet.setProperty("SERVERINSTANCE", "server instance name");
            propertySet.setProperty("DATABASE", "database name");
            propertySet.setProperty("DBCLIENT", "SQLServer");
            propertySet.setProperty("USER", "sql server user name");
            propertySet.setProperty("PASSWORD", "your password");
            //propertySet.setProperty("AUTHENTICATION_MODE", "DBMS");  // Optional.  DBMS is default
            //propertySet.setProperty("AUTHENTICATION_MODE", "OSA");   // Required if using operating sytem authentication

            IWorkspaceFactory workspaceFactory = new SqlWorkspaceFactory();
            IWorkspace workspace = new Workspace(workspaceFactory.open(propertySet, 0));

            IEnumDatasetName dsFeatureClassNames = workspace.getDatasetNames(esriDatasetType.esriDTAny);

            IDatasetName fcName = dsFeatureClassNames.next();
            while (fcName != null){
                System.out.println(fcName.getName());
                fcName = dsFeatureClassNames.next();
            }

        } catch (AutomationException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


Connecting to SDE would be:

            // Create a propertySet that contains the connection information to ArcSDE
            //  In ArcCatalog, the first three values are: server, service, database in the connection properties of the sde connection.
            IPropertySet propertySet = new PropertySet();
            propertySet.setProperty("SERVER", "server name");
            propertySet.setProperty("INSTANCE", "sde:sqlserver:server name");
            propertySet.setProperty("DATABASE", "database name");
            propertySet.setProperty("USER", "user name");
            propertySet.setProperty("PASSWORD", "user password");
            propertySet.setProperty("VERSION", "sde.DEFAULT");  // or whatever you call your version

            // Create a SdeWorkspaceFactory and open it
            IWorkspaceFactory sdeworkspaceFactory = new SdeWorkspaceFactory();
            IWorkspace workspace = new Workspace(sdeworkspaceFactory.open(propertySet, 0));
0 Kudos
VinceAngelo
Esri Esteemed Contributor
ArcObjects Java API is still in play for connecting to your database.


While this is true, installing ArcEngine and the ArcObjects SDK on a Linux box
might be a bit ungainly for what is probably a simple SQL statement.

- V
0 Kudos
LeoDonahue
Regular Contributor
yeah probably.  OP never said they wanted to do something easy after making the connection.
0 Kudos
MubasharAhmad1
New Contributor

I am trying to connect via direct connection to PostgreSQL spatial db. Java API version is 10.2 postgre 9.6 jdk 6. It successfully connects to database but when I call conn.getLayers() it says "Error getting layers" arcsde error -37 desc: DBMS TABLE DOES NOT EXIST. I dont know which table it is unable to find.

0 Kudos
VinceAngelo
Esri Esteemed Contributor

PostgreSQL 9.6 is not supported by geodatabases yet, so it can't have an Enterprise geodatabase, so ALL of the geodatabase tables are missing.

- V

0 Kudos
santhoshT
New Contributor II

 

 

Tags (1)
0 Kudos