Hide properties of database.jdbc.connection object
1 回表示 (過去 30 日間)
古いコメントを表示
I have a tool that connects to an SQL database using a jdbc driver. This tool has a function that looks something like this:
function conn = connect_to_sql_database(username, password)
key = '';
% Connect to the SQL database
conn = database([ '<URLOfSQLDatabase>;key=' key ], ...
username, password, ...
'<someJDBCDriver>', ...
'<SlightlyDifferentURLOfSQLDatabase>;key=' key ]);
The key is shared between many users, while username and password are personal. The key should not be visible to users, so I fill in the key and turn the function into p-code. However, when I run the function, it provides me an object of type database.jdbc.connection, which has properties DataSource and URL, which both contain key in plaintext. Is there any way in which I can hide these two properties or construct the connection in a different way so that key does not appear anywhere?
0 件のコメント
採用された回答
Dinesh
2023 年 11 月 17 日
Hi Jori.
I don't see a straight forward way to resolve your issue.
The classes defined inherently implement this behavior of exposing the URL. So, if you have the connection object, URL will be visible. However, custom classes can be created to replicate the same working but to hide the URL. This approach can lead to complications, but it seems like the only way to return a connection object and still not expose the URL. The following link will help you understand classes in MATLAB:
I would suggest a different implementation where you don't return the connection object to the user. Instead, the funcion can directly perform any operation that they want using that connection object and just return what is necessary for the user. This way, the connection URL will never be exposed.
I also don't understand the significance of using a key. If the above-mentioned approaches don't help you, could you please help me understand why a key is required along with the username and password so that I can look at this again and see if there is a better approach?
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Database Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!