Dear Experts
When we create table in MS Access we enter description of field in description column. I am able to get the field name and data type from the table but how can I get the description from the table.
Here is the code by which I am getting field name

public ArrayList<String> fetchtable(String value)
{
   try
   {
       makeConnection();
       String str1="Select * from "+ value;
       ResultSet rs = st.executeQuery(str1);
       rsmd = rs.getMetaData();
       NumOfCol= rsmd.getColumnCount();
       for(int i=1;i<=NumOfCol;i++)
       {
          ColumnName = rsmd.getColumnName(i);
          System.out.println(ColumnName);
          columns.add(ColumnName);
       }
      //System.out.println("Columns Valuessss is:" +columns);
    }catch(Exception ae){
      ae.printStackTrace();
     }
    return columns;
}

Kindly refer the image
4bfe0a317b79c671bff1964504f53eac

Dani AI

Generated

Short answer: the text shown in Access’s “Description” column is stored as the field’s Description property inside the Access file — it is not a regular SQL column comment that generic JDBC ResultSetMetaData will reliably return. Retrieving that Description requires an Access-aware API (Access DAO/ADOX via COM or a file-level reader like Jackcess). (learn.microsoft.com)

A practical Java path is to use the Jackcess library (pure Java, reads .mdb/.accdb). Open the database, get the Table, then read the Column’s PropertyMap and ask for the "Description" property (handle nulls if the property was never set). Example workflow (add Jackcess to the project, open the file, iterate columns, call getProperties().getValue("Description") and cast to String). Jackcess exposes Column.getProperties() and PropertyMap.getValue(...) for this exact use. (jackcess.sourceforge.io)

Alternatives and gotchas: ADOX/DAO can read and create the Description property (useful when working from a machine with Access/COM; examples exist in VB/ADOX). If the Description property does not exist for a field it must be created first (so code must test for null / missing property). Linked tables, permissions and database locking can affect access to system metadata. If a JDBC driver like UCanAccess is in use, check whether it surfaces remarks — but for a guaranteed, cross-platform Java solution Jackcess is the most direct approach. For Maven/Gradle the Jackcess artifact is available on Maven Central. (learn.microsoft.com)

Notes tied to the thread: ’s current ResultSetMetaData approach explains why column names and types are already visible; the Description lives in a different layer. Suggestions like reading label/metadata from standard JDBC metadata will normally not return Access’ Description — use an Access-specific reader or DAO/ADOX bridge when the Description text is required for UI/help text or export.

Recommended Answers

All 6 Replies

what is columns? where is this called?
do you get an error? do you get a stacktrace? do you get an unexpected result?
did you debug? or at least, add some print statements to see what ColumnName values are added? what is the input? what is the actual result?

can you show more of your code? if your calling method uses the same variables, are you sure they're nowhere being overwritten?

I suggest you start looking at naming conventions, it 'll make your code a lot easier to read/understand.

Have you tried getColumnLabel instead of getColumn Name ?

I already got the name of fields like ID and Name also I am able to get the data type like autonumber and Text but how to get the description like -Student Admission Number and Student Name, here I am stuck. I don't know what to use or how to get these descriptions

Vishalonne : why exactly do you need that? it's a bit like you put commentary in your class, and you expect another class to be able to read that using a getter ..

@JamesCherrill I already got the name of fields like ID and Name also I am able to get the data type like autonumber and Text but how to get the description like -Student Admission Number and Student Name, here I am stuck. I don't know what to use or how to get these description

Yes, but did you try getColumnLabel instead of getColumnName ?

I need this to know about the field for example if there is a field named as sgc type of this field is boolean and description of this field is Single Girl Child. My user will get the proper information regarding the field.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.