Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
90 lines (63 sloc) 3.01 KB

Simple Java Client

Level Technologies Target Product Product Versions Source

Beginners

Teiid, JDBC

DV

DV 6.1

https://github.com/teiid/teiid-quickstarts

What is it?

The sample client example can be used to test your sql queries against any server running a compatible Teiid Runtime and has an active VDB. This example will also be referenced by many of the other quick starts as a means to test suggested queries.

The JDBCClient.java is the example code that shows a developer the basic connection logic that can be used to connect to a Teiid instance running in a {{ book.asName }}.

The program expects four arguments. The pom.xml defines these arguments in the pom.xml:

<mainClass>JDBCClient</mainClass>
<arguments>
    <argument>${vdb}</argument>
    <argument>${sql}</argument>
</arguments>
Note
Notice that the and are preset. To point to a different server and/or port, change "localhost" and/or "31000" arguments, respectively, in the pom.xml.

In addition to above 6 parameter, the Simple client dependent on the following 4 system properties optionally:

  • host - define the host name of Teiid Server, default is localhost

  • port - define the port number of Teiid Server, dfault is 31000

  • username - define the username to connect to Teiid Server, default is teiidUser

  • password - define the password to connect to Teiid Server, default is password1!

  • showplan - whether show execution plan in sql execution, default is false

  • usedatasource = whether use org.teiid.jdbc.TeiidDataSource to create Connection, default if false

Note
If username, password not same as default, or want use TeiidDataSource to create Connection, showplan, use the system properties: -Dusedatasource=true -Dshowplan=true -Dusername=<username> -Dpassword=<password>

Prerequisites

Build

Build the project by running

mvn clean install

Execution

To execute a sql query using the simpleclient, use the following format:

mvn exec:java -Dvdb="<vdb>" -Dsql="<sql>" -Dusername="<username>" -Dpassword="<password> -Dusedatasource=true -Dshowplan=true"
Note
username, password, showplan, usedatasource are optional due to their default value.
A Example Executions
mvn exec:java -Dvdb="Portfolio" -Dsql="select * from Stock"
Note
The query is in quotes so that it is understood as a single argument. To run more advanced queries, it would be better a fully featured Java client, such as SQuirreL Client.
A Example of use TeiidDataSource
mvn exec:java -Dvdb="Portfolio" -Dsql="select * from Stock" -Dusedatasource=true
A Example of show execution plan
mvn exec:java -Dvdb="Portfolio" -Dsql="select * from Stock" -Dshowplan=true