4

Java ツール SAXON を使用してデータベースにクエリを実行したい

  1. ODBC 接続を使用して mysql データベースに接続する
  2. クエリ データベース (おそらく情報スキーマ - 読み取りスキーマ)
  3. 結果を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: オブジェクト.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

どんな種類の助けもかなりあります、ありがとう

4

1 に答える 1

1

次のプロセスを使用します。

  • MySQL Connector/J (MySQL の公式 JDBC ドライバー) をインストールします。
  • Apache Ant をインストールする
  • Ant タスクを作成/変更して、次のことを行います。
    • MySQL に接続する
    • クエリを実行
    • XML 出力を取得する
    • XML を Saxon 経由で処理する

参考文献

于 2014-04-25T04:16:01.380 に答える