sqlwrite() not working

5 次查看(过去 30 天)
Luis Davila
Luis Davila 2022-1-5
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 个评论
Kojiro Saito
Kojiro Saito 2022-1-12
What error message did you get from PostgreSQL server?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Database Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by