Pentaho PDI SDK:在输入步骤中重用SQL连接
我需要在Java代码中使用PDI SDK动态生成转换。转换输入是一个SQL选择,输出是一个文本文件 以下代码正确连接到输入步骤(TableInputMeta)的数据库: 其中Pentaho PDI SDK:在输入步骤中重用SQL连接,pentaho,kettle,Pentaho,Kettle,我需要在Java代码中使用PDI SDK动态生成转换。转换输入是一个SQL选择,输出是一个文本文件 以下代码正确连接到输入步骤(TableInputMeta)的数据库: 其中setConnection(conn)将现有连接链接到DatabaseMeta对象。有什么想法吗 更新: 我在Spoon中创建了一个JNDI连接,这是XML,但我不知道如何调整它以使其工作: <?xml version="1.0" encoding="UTF-8"?> <connection>
setConnection(conn)
将现有连接链接到DatabaseMeta对象。有什么想法吗
更新:
我在Spoon中创建了一个JNDI连接,这是XML,但我不知道如何调整它以使其工作:
<?xml version="1.0" encoding="UTF-8"?>
<connection>
<name>JNDI_CONNECT</name>
<server/>
<type>MYSQL</type>
<access>JNDI</access>
<database>JNDI_NAME</database>
<port>1521</port>
<username/>
<password>Encrypted </password>
<servername/>
<data_tablespace>TAB_DATA</data_tablespace>
<index_tablespace>TAB_IND</index_tablespace>
<attributes>
<attribute><code>FORCE_IDENTIFIERS_TO_LOWERCASE</code><attribute>N</attribute></attribute>
<attribute><code>FORCE_IDENTIFIERS_TO_UPPERCASE</code><attribute>N</attribute></attribute>
<attribute><code>IS_CLUSTERED</code><attribute>N</attribute></attribute>
<attribute><code>PORT_NUMBER</code><attribute>1521</attribute></attribute>
<attribute><code>QUOTE_ALL_FIELDS</code><attribute>N</attribute></attribute>
<attribute><code>STREAM_RESULTS</code><attribute>Y</attribute></attribute>
<attribute><code>SUPPORTS_BOOLEAN_DATA_TYPE</code><attribute>N</attribute></attribute>
<attribute><code>USE_POOLING</code><attribute>N</attribute></attribute>
</attributes>
</connection>
以下是我在Java中连接JNDI的方式:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/mydb");
Connection cn = ds.getConnection();
任何见解/工作示例都将不胜感激。您上面的示例XML将访问类型设置为“Native”,这将使用指定的参数。如果您想使用JNDI,应该将访问类型设置为JNDI。要获取XML的工作片段,请尝试在Spoon中为一些示例转换创建相同的连接,将转换保存到磁盘,然后检查.ktr文件以查找具有该名称的连接。您应该找到一个可用的XML代码段,它将让DatabaseMeta使用JNDI而不是提供的参数。谢谢,Matt。我添加了一个更新,似乎XML具有与JNDI无关的属性,例如数据库类型和端口号。
<?xml version="1.0" encoding="UTF-8"?>
<connection>
<name>JNDI_CONNECT</name>
<server/>
<type>MYSQL</type>
<access>JNDI</access>
<database>JNDI_NAME</database>
<port>1521</port>
<username/>
<password>Encrypted </password>
<servername/>
<data_tablespace>TAB_DATA</data_tablespace>
<index_tablespace>TAB_IND</index_tablespace>
<attributes>
<attribute><code>FORCE_IDENTIFIERS_TO_LOWERCASE</code><attribute>N</attribute></attribute>
<attribute><code>FORCE_IDENTIFIERS_TO_UPPERCASE</code><attribute>N</attribute></attribute>
<attribute><code>IS_CLUSTERED</code><attribute>N</attribute></attribute>
<attribute><code>PORT_NUMBER</code><attribute>1521</attribute></attribute>
<attribute><code>QUOTE_ALL_FIELDS</code><attribute>N</attribute></attribute>
<attribute><code>STREAM_RESULTS</code><attribute>Y</attribute></attribute>
<attribute><code>SUPPORTS_BOOLEAN_DATA_TYPE</code><attribute>N</attribute></attribute>
<attribute><code>USE_POOLING</code><attribute>N</attribute></attribute>
</attributes>
</connection>
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/mydb");
Connection cn = ds.getConnection();