Tuesday, November 2, 2010

Create a SQL query at runtime in Application Module

We should use view object and related view criteria or bind variable to get any values from the database. Even though it is not recommended in many reasons, you still could try this way if the query is simple and trying to get a single value from the query.

In your application module implementation file, you could use getDBTransaction().createStatement() method to execute a sql query at run time.

Note there are three SQL statement types available in the DBTransaction interface: statement, callableStatement and preparedStatement.

Here is the snippet of coding in your application module file:

2 comments:

Andrew Wong said...

We need to close the created statement before return, right?

JayJay Zheng said...

That's correct. The connection needs to be closed after use, otherwise it will cause JDBC connection leak.