sqlwrite() not working

조회 수: 4 (최근 30일)
Luis Davila
Luis Davila 2022년 1월 5일
댓글: Kojiro Saito 2022년 1월 12일
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