如何检查 OpenSQLConnection 是否成功(在 Mathematica 中)?
如何检查 DatabaseLink`OpenSQLConnection 是否成功?我的代码如下
conn = OpenSQLConnection[JDBC["hsqldb", "file"], "Name"-> "test"];
我可以使用类似 Head[conn] 的东西吗?
How can I check if DatabaseLink`OpenSQLConnection was successful? My code is as follows
conn = OpenSQLConnection[JDBC["hsqldb", "file"], "Name"-> "test"];
Can I use something like Head[conn]?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
成功连接的返回值将有头
SQLConnection
(在DatabaseLink
上下文中)更一般地说:
OpenSQLConnection
返回$Failed
> 当连接由于任何原因失败时:...并且当其参数的形式不正确时未计算:
因此,您可以查找
$Failed
的返回值,也可以选择使用检查[...]
以捕获并处理生成的消息。正如您所猜测的,您可以使用Head[returnvalue]
来确保返回值的头部不等于OpenSQLConnection
。The return value for successful connection will have head
SQLConnection
(in theDatabaseLink
context)More generally:
OpenSQLConnection
returns$Failed
when the connection failed for whatever reason:... and unevaluated when its arguments were not of the proper form:
Therefore, you can look for a return value of
$Failed
and optionally also useCheck[...]
to trap and handle messages that were generated. As you guessed, you can useHead[returnvalue]
to make sure the head of the return value does not equalOpenSQLConnection
.这并不完全是您问题的答案,但这是我为了可靠地连接到我的数据库所做的事情:
This is not exactly an answer to your question, but this is what I do to connect reliably to my database: