Validating table and field names

In this topic

About validating table and field names

Geodatabases use various relational database management systems (RDBMS) to maintain the tables that comprise a geodatabase. All tables in a geodatabase must have a unique name, so a mechanism for checking if a table name is unique is essential when creating data in a geodatabase. If you are setting overwrite output to true, there is potential for accidentally overwriting data. Using the ValidateTableName method, a program can determine if a specific name is valid and unique to a specific workspace.

Validating table names

Specifying the workspace as a parameter allows the geoprocessor to check all the existing table names and determine if there are naming restrictions imposed by the output workspace. If the output workspace is a RDBMS, it can have reserved words that may not be used as a table name. It can also have invalid characters that are not to be used in a table or field name. ValidateTableName returns a string representing a valid table name that can be the same as the input name if the input name is valid. The following code example guarantees that a new output feature class is created by the Copy Features tool:
gp.setEnvironmentValue("workspace", "C:/program files/arcgis/java/samples/data/usa");
IGpEnumList shapefiles = gp.listFeatureClasses("", "", "");
String outWorkspace = "C:/program files/arcgis/java/samples/output_data";
CopyFeatures copyFeatures = new CopyFeatures();
String shapefile =;
while (!"" .equals(shapefile)){
    //Validate the output name so it is unique and not empty.
    String outfc = gp.validateTableName(shapefile, outWorkspace);
    copyFeatures.setOutFeatureClass(outWorkspace + "/" + outfc);
    gp.execute(copyFeatures, null);
    //Grab the next shapefile.
    shapefile =;

Validating field names

Each database can have naming restrictions for field names in a table. Objects, such as feature classes or relationship classes are stored as tables in a RDBMS, so these restrictions affect more than just stand-alone tables. These restrictions may or may not be common between various database systems, so programs should check all new field names to ensure that a tool does not fail during execution.
The following code example ensures that a field is added regardless of the input name, using the ValidateFieldName method:
    "C:/program files/arcgis/java/samples/output_data/usa.gdb");
//Dog count is invalid for the .gdb file, converting it to dog_count.
String fieldName = gp.validateFieldName("dog-Count", 
    "C:/program files/arcgis/java/samples/data/usa/states.shp");
AddField addField = new AddField("states.shp", fieldName, "TEXT");
gp.execute(addField, null);
When a program updates a dataset, such as a feature class or table, be careful to avoid situations where the dataset is locked. For example, Microsoft Access always locks a database for update operations when a table is accessed, so if you have a personal geodatabase open in ArcCatalog, a program cannot update any of the geodatabase's contents until it is deselected and the folder is refreshed or ArcCatalog is closed.