# Best way to get a JDBC connection inside a custom transform?

**URL:** <https://forum.cloverdx.com/t/best-way-to-get-a-jdbc-connection-inside-a-custom-transform/1031>\
**Category:** CloverDX Platform\
**Created:** [March 17, 2012, 12:00am UTC](https://forum.cloverdx.com/t/best-way-to-get-a-jdbc-connection-inside-a-custom-transform/1031 "2012-03-17T00:00:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidleelambert](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.cloverdx.com/davidleelambert/32/78_2.png) [@davidleelambert](https://forum.cloverdx.com/u/davidleelambert)\
**Post date:** [March 17, 2012, 12:00am UTC](https://forum.cloverdx.com/t/best-way-to-get-a-jdbc-connection-inside-a-custom-transform/1031/1 "2012-03-17T00:00:00Z")

</div>

I’m writing some CloverETL graphs that have one JDBC source connection and write one or more flat files. One of the problems I need to solve is mismatch between the data-format of certain database fields and how they are supposed to appear in the flat file. I have a database table that provides the lookup information I need; however, I don’t want to use a CloverETL DBJoin or LookupJoin node to solve it, because I have many fields in the record that all need the exact same transformation.

Is there an easy way of getting the set of all JDBC connections defined in the current graph, from within custom transformation code (that is, from within a class that implements “org.jetel.component.DataRecordTransform” and whose fully-qualified name is used as the value of the “Transform class” property of a node)?

(for my particular problem, so far, I can assume that there is only one such connection, and that it is suitable for that purpose; if there was more than one, could I choose a particular one by ID, or by its “name” property?)

---

<div class="post-metadata">

**Author:** ![mzatopek](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@mzatopek](https://forum.cloverdx.com/u/mzatopek)\
**Post date:** [March 19, 2012, 12:35pm UTC](https://forum.cloverdx.com/t/best-way-to-get-a-jdbc-connection-inside-a-custom-transform/1031/2 "2012-03-19T12:35:27Z")

</div>

Within your custom transformation code you can easily get a connection with following code:

```auto
public class MyTrans extends DataRecordTransform {
...
public boolean init() {
  DBConnection bdConnection = getGraph().getConnection(parameters.getProperty("myCustomPropertyNameWithConnectionId"));
  //OR
  for (String connectionId : getGraph().getConnections()) {
    bdConnection = (DBConnection) getGraph().getConnection(connectionId);
  }
  return true;
}

```

Variable _parameters_ is available from _DataRecordTransform_ class and contains all custom attributes of your Reformat component:

```auto
<Node enabled="enabled" guiName="Reformat" id="REFORMAT1" type="REFORMAT" myCustomPropertyNameWithConnectionId="connectionId">

```

Martin
