【发布时间】:2013-01-22 13:55:48
【问题描述】:
我想使用java工具SAXON查询数据库
- 使用 ODBC 连接连接到 mysql 数据库
- 查询数据库(可能是信息架构-读取架构)
- 将结果导出到 xml 中
这是 saxon 中的许可功能(例如 saxon9ee)吗?
如果是 是否有任何其他开源选项可以实现相同级别的功能?
我已经下载了 saxon9ee.jar + saxon9he.jar 并玩了一下。
到目前为止我做了什么:
XSLT:connect.xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
xmlns:sql="http://saxon.sf.net/sql"
extension-element-prefixes="sql"
version="2.0">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:param name="driver" select="'com.mysql.jdbc.Driver'"/>
<xsl:param name="database" select="'jdbc:mysql://localhost/databaename'"/>
<xsl:param name="user" select="'usr'"/>
<xsl:param name="password" select="'pwd'"/>
<xsl:template match="//databaseObjects">
<xsl:message>Connecting to database...</xsl:message>
<!-- The "connection" variable establishes JDBC connection by selecting as its value the SQL connection to the database.!-->
<xsl:variable name="connection" as="java:java.lang.Object" xmlns:java="http://saxon.sf.net/java-type">
<sql:connect driver="{$driver}" database="{$database}" user="{$user}" password="{$password}">
<!-- Used primarily for debugging, if,
for whatever reason, the credentials or something incorrect is passed in the connect statement,
the process will terminate with the following message -->
<xsl:fallback>
<xsl:message terminate="yes">Connection to MySQL failed.</xsl:message>
</xsl:fallback>
</sql:connect>
</xsl:variable>
<sql:close connection="$connection"/>
</xsl:template>
</xsl:stylesheet>
XML:objects.xml
(粗略的想法)
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseObjects>
<object type="triggers"/>
<object type="functions"/>
<object type="procedures"/>
<object type="views"/>
<object type="events"/>
</databaseObjects>
命令:
java -jar ~/saxon/saxon9he.jar objects.xml connect.xslt
输出:
No license file found - running with licensable features disabled
Connecting to database...
Error on line 17 of connect.xslt:
XTDE1450: Unknown extension instruction
in built-in template rule
Transformation failed: Run-time errors were reported
任何形式的帮助都是可观的,谢谢
【问题讨论】:
-
SQL 扩展在 Saxon HE 中不可用:saxonica.com/feature-matrix.html。
-
Saxon EE 怎么样,还有哪些其他选择?
-
@mzjn 谢谢,在这种情况下,我正在寻找开源解决方案
-
如果您的时间多于金钱,那么 Saxon 的 SQL 扩展实际上是作为开源代码发布的,您可以自己编译它并将其与 Saxon-HE 集成。它只是没有“开箱即用”地与 Saxon-HE 集成。
-
@MichaelKay,感谢您的建议,这似乎是个好机会
标签: java mysql xslt saxon jdbc-odbc