Clear Filters
Clear Filters

Unmatched parameter name error when connecting to a PostgreSQL database

20 views (last 30 days)
I want to connect to a PostgreSQL database. I've the database toolbox.
When I insert data i obtain an error:
databaseLink = "jdbc:postgresql://" + options.getHostname() + ":" + options.getPort() + "/" + options.getDatabaseName();
this.connection = database( ...
options.getDatabaseName(), ...
options.getUsername() , ...
options.getPassword() , ...
"org.postgresql.Driver" , ...
databaseLink ...
The error is
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.
How can I fix this error?
I went on the error line and I've found that It's connecting to database inside this:
function connection = database(varargin)
%DATABASE Connect to database.
% returns a database connection object. Datasource can be a JDBC or ODBC
% data source. Username and Password should be provided as required for
% authorization and authentication by the database.
% Parameter Value Default
% ------------ ------------ -------
% AUTOCOMMIT 'on' | 'off' 'on'
% LOGINTIMEOUT 0 | double 0
% READONLY 'on' | 'off' 'off'
% ERRORHANDLING 'report' | 'store' setdbprefs('ErrorHandling')
% Example:
% --------
% JDBC connection:
% ----------------
% conn=database('jdbcdatasource','scott','tiger')
% where:
% 'jdbcdatasource' is the JDBC datasource name created using configureJDBCDataSource.
% 'scott' is the user name.
% 'tiger' is the password.
% ODBC connection:
% ----------------
% conn=database('odbcdatasource','scott','tiger')
% where:
% 'odbcdatasource' is the ODBC datasource name created using configureODBCDataSource.
% 'scott' is the user name.
% 'tiger' is the password.
% database methods:
% -----------------
% sqlwrite - Insert MATLAB data into database table.
% sqlread - Import data into MATLAB from database table.
% sqlfind - Find information about all table types in
% database.
% sqlinnerjoin - Inner join between two database tables.
% sqlouterjoin - Outer join between two database tables.
% execute - Execute SQL statement using relational
% database connection.
% fetch - Import data into MATLAB using connection handle.
% isopen - Detect if database connection is open/close.
% close - Close database connection.
% commit - Make database changes permanent.
% rollback - Undo database changes.
% update - Replace data in database table with data from MATLAB.
% Copyright 1984-2019 The MathWorks, Inc.
connection = database.internal.utilities.hdatabase(varargin{:});
I've put a breakpoint in there and varargin is:
varargin =
1×5 cell array
{["wtrade"]} {["postgres"]} {["squall"]} {'org.postgresql.Dr…'} {["jdbc:postgresql…"]}
But from the description of the function instead of 'org.postgresql.Driver' there should be AUTOCOMMIT, LOGINTIMEOUT, READONLY or ERRORHANDLING. So this is the error. But I'm using the database function in the right way, according to documentation example, so why I obtain this error, and how can I connect in the right way?

Accepted Answer

Daniele Lupo
Daniele Lupo on 4 Nov 2019
I've got the solution by myself, even if it's not as straightforward as I've supposed.
My database name is wtrade.
In order to test it, I opened the database explorer of matlab and I've created a new connection. I called this connection wtrade as well.
When I call the database function in order to get the connection, the inner code at first look if there's a connection with the name that I give with first argument, and if not it goes ahead. Since I had a connection named the same way as the database, it started the initialization code of following signature:
conn = database(datasource,username,password)
instead of this one
conn = database(databasename,username,password,driver,url)
since datasource and databasename were the same.
The first signature accept name values pairs Name, value, and since driver value is not one of accepted parameter values of course, like "Name" or "Vendor" (check database documentation for this), I got the error, that says clearly (now) that the string in "driver" position is not the name of an accepted parameter like "Name" or "Vendor"
In order to solve it I've deleted the connection that I've created with database explorer and it works. My opinion anyway is that's a bug, since it's normal and not forbidden to have a datasource with the same name of the database.

More Answers (2)

the cyclist
the cyclist on 1 Nov 2019
Edited: the cyclist on 1 Nov 2019
I am not able to test this right now, but it seems possible to me that MATLAB wants single quotes instead of double quotes around org.postgresql.Driver.
The error message says a string scalar should be ok, so I'm pessimistic that this is the solution. But I've only ever used single quotes there, and it is an easy thing to try.
Similarly, the complaint might actually be about the value in that name-value pair. So maybe make databaseLink into a character array instead of a string as well.

the cyclist
the cyclist on 3 Nov 2019
Sorry for the delayed reply, and I truly don't know if this will help or not. It does not seem to directly related to your error message, but I figured it doesn't hurt to suggest it!
In my equivalent of your databaseLink variable, my string ends with the port number and then a slash. It does not have the database name as part of it.




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!