sqlwrite() not working

4 views (last 30 days)
Luis Davila
Luis Davila on 5 Jan 2022
Commented: Kojiro Saito on 12 Jan 2022
I am working on a database project, and am trying to create a JDBC datasource in matlab using code instead of the Database toolbox.
I use the following code to create a database connection.
vendor = "PostgreSQL";
opts = databaseConnectionOptions("native",vendor);
opts = setoptions(opts, ...
'DataSourceName',"second_test", ...
'DatabaseName',"postgres",'Server',"localhost", ...
'PortNumber',5432);
%test the connection, this should return a 1 if the test is passed
status = testConnection(opts,username,password);
%saves the datasource
saveAsDataSource(opts)
%data1 should be a row of data
data1 = table("a","b","c",'VariableNames',["one","two","three"]);
%should create a connection to the database, and seemingly does
conn = postgresql('second_test',username,password);
%should write the row data1 to the table, this is where it fails, the table
%is not actually written to
sqlwrite(conn,table,data1)
The data source is successfully saved, but sqlwrite(conn,tablename,data1) fails, because no new rows are written to the table. I believe the problem is I'm setting the wrong options, but I don't know what the right options are. If someone could please shed some light I would be very appreciative.
  1 Comment
Kojiro Saito
Kojiro Saito on 12 Jan 2022
What error message did you get from PostgreSQL server?

Sign in to comment.

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!