wolfram-mathematica - 如何检查 OpenSQLConnection 是否成功(在 Mathematica 中)?

标签 wolfram-mathematica

如何检查 DatabaseLink`OpenSQLConnection 是否成功?我的代码如下

conn = OpenSQLConnection[JDBC["hsqldb", "file"], "Name"-> "test"];

我可以使用 Head[conn] 之类的东西吗?

最佳答案

成功连接的返回值将有头SQLConnection(在DatabaseLink上下文中)

更一般地说:

OpenSQLConnection 当连接因任何原因失败时返回 $Failed:

In[25]:= OpenSQLConnection[JDBC["mysql", "localhost:3306/foo"], 
   "Username" -> "foo", "Password" -> "bar"]

During evaluation of In[25]:= JDBC::error: Access denied for user 'foo'@'localhost' (using password: YES) >>

Out[25]= $Failed 

...并且当其参数不符合正确形式时未计算:

In[28]:= OpenSQLConnection[Sin[x]]

Out[28]= OpenSQLConnection[Sin[x]]

因此,您可以查找返回值 $Failed,也可以选择使用 Check[...] 来捕获和处理生成的消息。正如您所猜测的,您可以使用 Head[returnvalue] 来确保返回值的头部不等于 OpenSQLConnection

关于wolfram-mathematica - 如何检查 OpenSQLConnection 是否成功(在 Mathematica 中)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2511463/

相关文章:

wolfram-mathematica - 像 :sub: defined? 这样的排版快捷键在哪里

wolfram-mathematica - 如何捕获由TimeConstrained生成的中断?

matrix - 在 Mathematica 中选择/删除矩阵中的行/列列表的有效方法

wolfram-mathematica - 数学中的消息生成

wolfram-mathematica - 将笔记本集成到 Mathematica 的文档中心

wolfram-mathematica - 在 Mathematica 和 MIDI 踏板事件中叠加音乐轨道

wolfram-mathematica - 数学 : Solving a PDE that contains Conjugate of a function or Abs of a function

python - python中有 "apply"这样的东西吗?

math - 如何在mathematica中定义使用复杂递归关系的函数?

wolfram-mathematica - 打印 Grid with list in list 作为 Wolfram Alpha 的输出