1

I'm trying to connec to a PostgreSQL database with following command:

connection = database( ...
        options.getDatabaseName(), ...
        options.getUsername(), ...
        options.getPassword(), ...
        "org.postgresql.Driver", ...
        "jdbc:postgresql://" + options.getHostname() + ":" + options.getPort() + "/" + options.getDatabaseName() ...
        );

It returns me following error:

Error using database (line 59)
Unmatched parameter name 'org.postgresql.Driver' must be a string scalar or character vector that can represent a field name.

I've seen other questions about that, like this one but the error message is different.

What I'm doing wrong?

3
  • Sure looks like you're doing it right. The database() signature is kind of wonky. What happens if you use char arrays (single-quoted) instead of string arrays (double-quoted) in your arguments? Commented Nov 5, 2019 at 8:26
  • Also make sure that the first three optiosn.getDatabaseName() etc. arguments are not returning empty; that might foul up database()'s signature parsing heuristics. Commented Nov 5, 2019 at 8:28
  • BTW, what version of Matlab, and what OS are you running on? I could pull up the source and look at it. Commented Nov 5, 2019 at 8:28

1 Answer 1

0

I've found the solution by myself, and it's tricky (maybe related to a bug in my opinion).

In order to test the database connection I've created first a connection with the Database explorer. It worked, and I saved this connection using the same name of the database.

When I use the database command, by inspecting it source code I've seen that the first thing that it does it to check if there's an existing data source with that name and, if not, it search for the database. The problem was that since my connection had the same database name, database supposed that I wanted to use the data source command version instead of the database. It tried to use this command:

conn = database(datasource,username,password)

instead of this one:

conn = database(databasename,username,password,driver,url)

since wtrade is both name of the database and of the data source. In that case the fourth argument, driver, must be a parameter name, like "Vendor" of "PortNumber", as per Matlab documentation, so since the driver string does not match a parameter name, I had the error.

I've removed the datasource with the same name of the database and everything started to work.

I've notified this to MathWorks, since in my opinion there should be no problem if a database has the same name of a datasource, since the signature are different, so database command should handle also this case.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.