Execute query against database.

JDBC driver library file(s) should be provided on the classpath if used programatically, or on the same path with Web-Harvest executable if used standalone. In case of SELECT sql statement, it returns list of row objects. They can be accessed with special accessor methods:


<mydbrow>.getColumnCount() - returns number of columns returned.
<mydbrow>.getColumnName(index) - returns name for column number.
<mydbrow>.get(column_index) - returns field value for column number.
<mydbrow>.get(column_name) - returns field value for column name.

The whole list of returned db rows can be accessed by index to get individual row:


<mydbvar>.get(rowindex)

For example:


mydb.get(0).get("image")

Syntax

<database connection="jdbc connection string"
          jdbcclass="full named jdbc class"
          username="username"
          password="password"
          autocommit="autocommit"
          max="max rows returned">
    select, insert or delete SQL query
</database>

Attributes

Name Required Default Description
connection yes Properly formatted JDBC string for the database. It depends on database/driver vendor.
jdbcclass yes Fully qualified class name of the JDBC driver.
username no Username to access database.
password no Password to access database.
autocommit no true Whether commit is performed automatically after query execution.
max no no limit Maximum number of returned rows from the SELECT statement.

Example 1

<var-def name="employees">
    <database connection="jdbc:microsoft:Sqlserver://myserver:1433;databaseName=mycompany;user=sa;password=hehehe"
              jdbcclass="com.microsoft.jdbc.sqlserver.SQLServerDriver">
        select name, salary from employee
    </database>
</var-def>

<loop item="emp">
    <list>
        <var name="employees"/>
    </list>
    <body>
        <template>Salary of ${emp.get("name")} is ${emp.get("salary")}</template>
    </body>
</loop>

Example 2

<database connection="jdbc:microsoft:Sqlserver://myserver:1433;databaseName=mycompany;user=sa;password=hehehe"
          jdbcclass="com.microsoft.jdbc.sqlserver.SQLServerDriver">
    <template>
        insert into news (id, url, text, source)
        values (${myId}, '${myUrl}', '${myText}', '${mySource}')
    </template>
</database>