Needs["DatabaseLink`"]
conn = DatabaseLink`OpenSQLConnection[
DatabaseLink`JDBC[ "MySQL(Connector/J)",
"localhost:3306/railfreight"], "Username" -> "",
"Password" -> ""]
(* SQLConnection[1, "Open", "Catalog" -> "railfreight",
"TransactionIsolationLevel" -> "RepeatableRead"]*)
But when you check out the FullForm
(removed password info):
FullForm[conn]
(* SQLConnection[JDBC["MySQL(Connector/J)","localhost:3306/railfreight"],JLink`Objects`vm1`JavaObject121074792529921,2,Rule["Catalog",Automatic],Rule["Description",None],Rule["Location",None],Rule["Name",None],Rule["Password",""],Rule["Properties",List[]],Rule["ReadOnly",Automatic],Rule["RelativePath",False],Rule["TransactionIsolationLevel",Automatic],Rule["UseConnectionPool",Automatic],Rule["Username",""],Rule["Version",None]] *)
Similarly when you close the connection:
CloseSQLConnection[conn]
FullForm[conn]
(* SQLConnection[JDBC["MySQL(Connector/J)","localhost:3306/railfreight"],Removed["JavaObject341542795476993"],1,Rule["Catalog",Automatic],Rule["Description",None],Rule["Location",None],Rule["Name",None],Rule["Password",""],Rule["Properties",List[]],Rule["ReadOnly",Automatic],Rule["RelativePath",False],Rule["TransactionIsolationLevel",Automatic],Rule["UseConnectionPool",Automatic],Rule["Username",""],Rule["Version",None]] *)
So based on that I think this is worth a try:
Cases[SQLConnections[], SQLConnection[_, Except[_Removed], __]]
SQLConnections[] // FullForm
shows why the pattern matching fails. $\endgroup$