Unmatched parameter name error when connecting to a PostgreSQL database
Ältere Kommentare anzeigen
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?
EDIT:
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.
% CONNECT = DATABASE(DATASOURCE,USERNAME,PASSWORD, 'PARAM', 'VALUE')
% 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{:});
end
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?
Akzeptierte Antwort
Weitere Antworten (2)
the cyclist
am 1 Nov. 2019
Bearbeitet: the cyclist
am 1 Nov. 2019
0 Stimmen
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.
1 Kommentar
Daniele Lupo
am 1 Nov. 2019
the cyclist
am 3 Nov. 2019
0 Stimmen
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.
1 Kommentar
Daniele Lupo
am 4 Nov. 2019
Kategorien
Mehr zu Database Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!