virtuoso-opensource icon indicating copy to clipboard operation
virtuoso-opensource copied to clipboard

Missing column with Å,Ä,Ö

Open saruganiquest opened this issue 10 months ago • 6 comments

  @Override
    public List<Map<String, String>> getData(String query) throws ConnectionErrorException
    {
        if (query == null || query.isEmpty()) {
            throw new IllegalArgumentException("Query cannot be null or empty");
        }
        this.setupConnection();
        
        try {
            TupleQuery tupleQuery = this.getRepositoryConnection().prepareTupleQuery(QueryLanguage.SPARQL, query);
            tupleQuery.setMaxExecutionTime(MAX_SPARQL_QUERY_EXECUTION_TIME);
            TupleQueryResult result  = tupleQuery.evaluate();
            return this.parseResult(result);
        } catch (Exception e) {
            throw new ConnectionErrorException(e);
        }
    }
private List<Map<String, String>> parseResult(TupleQueryResult result)
    {
        List<Map<String, String>> resultsList = new ArrayList<>();
        while (result.hasNext()) {
            BindingSet bindingSet = result.next();
            Map<String, String> row = new HashMap<>();
            
            for (Binding binding : bindingSet) {
                row.put(binding.getName(), binding.getValue().stringValue());
            }
            resultsList.add(row);
        }
        
        return resultsList;
    }

I have this code and when i run the query i am not getting the values for the following columns att_instÅr and att_Betjänar. The BindingNames have them but they are missing in the BindingSet.

Image

Image

They have values in the database, i tested running it in the webinterface and there it works correctly.

saruganiquest avatar Feb 11 '25 14:02 saruganiquest

Is it using the RDF4J provider or what? How did you create VirtuosoRepository object, I do mean parameters? Note, you must use charset=UTF-8 to properly work with Unicode. The charset=UTF-8 is automatically set only for constructors like:

VirtuosoRepository repository = new VirtuosoRepository("localhost:1111", "uid**", "pwd**");

If you create it via DataSource, you must set this option yourself.

smalinin avatar Feb 11 '25 18:02 smalinin

protected void setupRepository() throws ConnectionErrorException
   {
       try {
           if (this.isRepositoryConnectionActive()) {
               this.logger.warn("Repository connection is already active. Closing it and opening a new one");
               this.closeRepositoryConnection();
           }
           
           String url = String.format("jdbc:virtuoso://%s:%d/sparql?charset=UTF-8", this.getAddress(), this.getPort());
           this.setRepository(new VirtuosoRepository(url, this.getUsername(), this.getPassword()));
           this.getRepository().initialize();
           this.getRepository().setQueryTimeout(MAX_SQL_QUERY_EXECUTION_TIME);
           this.getRepository().setConcurrencyMode(VirtuosoRepository.CONCUR_OPTIMISTIC);
           
           this.setRepositoryConnection(this.getRepository().getConnection());
       } catch (Exception e) {
           throw new ConnectionErrorException("Failed to setup repository", e);
       }
   }

Yes i have tried adding charset=UTF-8 but i still have the same problem.

saruganiquest avatar Feb 12 '25 08:02 saruganiquest

Hi, some update on the problem. When using http request i am able to get the att_instÅr and att_Betjänar. But it is when using JDBC connection that the problem arises.

saruganiquest avatar Feb 17 '25 12:02 saruganiquest

When making the JDBC connection, you are not passing the charset=UTF-8 param correctly, as it should be delimited with a / (slash) as part of the JDBC connect string — not a ? (question mark), which is an HTTP URL param delimiter.

In fact, I don't understand the connect string being passed, i.e., "jdbc:virtuoso://%s:%d/sparql?charset=UTF-8", as "jdbc:virtuoso:// is a valid Virtuoso JDBC connect string specifier, but %s:%d/sparql?charset=UTF-8" part would be for an HTTP URL to the Virtuoso SPARQL endpoint.

So, are you seeking to make a JDBC connection to the Virtuoso SQL database, or an HTTP connection the Virtuoso SPARQL endpoint?

I would assume the former, in which case the JDBC connect string should be of the form:

"jdbc:virtuoso://hostname:portno/charset=UTF-8/"

where portno is the SQL (i.e., 1111, by default) and not the HTTP (i.e., 8890, by default) port number of the Virtuoso database instance you are seeking to connect to, as in this example program.

HughWilliams avatar Feb 17 '25 13:02 HughWilliams

Yes, i have tried that aswell, and it still doesnt get those values in the bindingSet.

Image

Image

saruganiquest avatar Feb 17 '25 15:02 saruganiquest

It works properly for me:

Sample:

Test_Unicode.java.txt

Output from console:

Image

May be your data was unproperly inserted. Execute select via HTTP SPARQL endpoint and look on RAW output

smalinin avatar Feb 26 '25 01:02 smalinin