Menu

Fetch data from Tag datatype column in MSAccess

LOKA PRABA
2018-05-09
2020-04-03
  • LOKA PRABA

    LOKA PRABA - 2018-05-09

    Hi,

    Is there any way that we can get the value from a TAG type column as a single value. If the TAG field contains multiple values it should be clubbed using some delimiter like comma and returned.

    Also is there any document listing the type information and handling the each type from the resultset.

     
  • Gord Thompson

    Gord Thompson - 2018-05-09

    Check the "Working with Complex Types" section of the Getting Started page of the website. Multi-value lookup fields are returned as an array of net.ucanaccess.complex.SingleValue objects. If you want a single delimited list of values you could build it by iterating over that array.

     
  • Gord Thompson

    Gord Thompson - 2018-05-09

    Example: For a table named [Donors]

    Donors.png

    we can use the following code in Java 8:

    String sql = "SELECT DonorType FROM Donors WHERE ID=3";
    Statement st = conn.createStatement();
    ResultSet rs = st.executeQuery(sql);
    rs.next();
    List<SingleValue> donorTypeList = Arrays.asList((SingleValue[]) rs.getObject(1));
    String donorTypeString = String.join(
            ", ", 
            donorTypeList.stream().map(x -> x.getValue().toString()).collect(Collectors.toList()));
    // donorTypeString contains "Corporate, International"
    
     
  • James Cafferkey

    James Cafferkey - 2020-04-02

    Hi Gord
    Im new to using ucanaccess but i have put together a piece of java code to access a microssoft access database and retrieve value from it using Resultset rs.getString("Identifier") function okay. this works for a single entry field.

    i am however having an issue with database entry that has multiple values in one field.
    i am trying to use below code

        rs.getObject("identifier");
               String  Reticle_test =rs.getObject("identifier").toString();
                System.out.println(" multiple items in field are "+Reticle_test);
    
               but i keep getting the below output
    
              Lnet.ucanaccess.complex.SingleValue;@4c9859cf"
    
              Any help would be appreciated
    
    
             Attached is image of database, items i am struggling to retrieve are the multiple entries in under Reticles header.
    
              James
    
     
  • Gord Thompson

    Gord Thompson - 2020-04-03

    Have a closer look at the example code in my previous post. For a multi-valued lookup field getObject returns an array of SingleValue objects that you need to "stringify". Simply calling toString just shows you the string representation of the object, not its contents.

     

Log in to post a comment.