Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing column with Å,Ä,Ö #1342

Open
saruganiquest opened this issue Feb 11, 2025 · 6 comments
Open

Missing column with Å,Ä,Ö #1342

saruganiquest opened this issue Feb 11, 2025 · 6 comments
Assignees

Comments

@saruganiquest
Copy link

saruganiquest commented Feb 11, 2025

  @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.

@smalinin
Copy link
Collaborator

smalinin commented Feb 11, 2025

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.

@saruganiquest
Copy link
Author

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
Copy link
Author

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.

@HughWilliams
Copy link
Collaborator

HughWilliams commented Feb 17, 2025

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.

@saruganiquest
Copy link
Author

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

Image

Image

@smalinin
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants