2013-01-22 48 views
4

我想用java工具SAXON我需要什麼使用Saxon java工具(命令行)從xsl查詢mysql數據庫?

  1. 使用ODBC連接到數據庫查詢連接到MySQL數據庫
  2. 查詢數據庫(可能是信息架構 - 讀取模式)
  3. 將結果導出到XML

這是撒克遜許可的功能(例如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

任何形式的幫助是明顯的,由於

+0

的SQL擴展,不提供在撒克遜HE:http://www.saxonica.com/feature-matrix.html。 – mzjn

+0

撒克遜EE呢,還有什麼其他選擇? – sakhunzai

+0

@mzjn謝謝,我正在尋找開源解決方案,在這種情況下 – sakhunzai

回答

1

使用以下過程:

  • 安裝MySQL Connector/J(MySQL的官方JDBC驅動程序)
  • 安裝Apache Ant
  • 創建/修改Ant t問:
    • 通過撒克遜連接到MySQL
    • 運行查詢
    • 獲取XML輸出
    • 處理XML

參考

相關問題