Hi again Boerries,

Ludwig, Boerries wrote:
> Hi,
> 
> I have a similar problem. My application allows the administrator to query
> the database with SQL-statements. I had my own connections to HSQL, but now
> I get "java.sql.SQLException: The database is already in use by another
> process". The other process ist OJB.

AFAIK HSQLDB does only allow single user access. You must run it in 
server mode to allow multiple clients.

> 
> My questions are:
> 
> 1. can I pass SQL-statements to OJB (the solution from Jakob does not help)

Yes. There is a QueryBySQL class that allows freeform SQL.
1. If you use such a QueryBySQL q with a PB.getCollectionByQuery(q) the 
class specified is used to materialize concrete instances filled from 
the resultset of the query. Thus the columns of the sql statement must 
match the class-descriptor layout for that class.
2. If you use it within a PB.getReportQueryIteratorByQuery(q) the class 
is ignored. Thus the SQL does *not* need to match the class layout!

> 2. can I reuse a connection from OJBs connetion-pool to pass my query to
> 

Yes. Have a look at the org.apacha.ojb.PerformanceJdbcReferenceTest to 
see how this is done.

cheers,
Thomas

> Thanks in advance
> 
>    Boerries
> 
> .............................
> 
> hi ronen,
> 
> you could also use a report query to retrieve simple column data:
> 
> crit = new Criteria();
> crit.addEqualTo("name", "%er");
> query = new ReportQueryByCriteria(Person.class, crit);
> query.setColumns(new String[] { "sum(test)" });
> broker.getReportQueryIteratorByQuery(query);
> 
> hth
> jakob
> 
> ----- Original Message -----
> From: <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, August 07, 2002 2:32 PM
> Subject: Simple SQL Query
> 
> 
> 
>>Hello everyone.
>>
>>i have a quick question which i'm sure you guys would know.
>>In my database, I have a table called "PRODUCTS" which has a column called
>>"ID".  (this table maps to the persistent class Product.java).  What i'm
>>simply trying to do is to use an sql statement to find out how many
>>products there are in the "PRODUCTS" table.
>>
>>The code I am using is:
>>
>>Criteria criteria = new Criteria();
>>criteria.addSql( "SELECT COUNT(ID) FROM PRODUCTS;" );
>>
>>The problem is that this sql statement should simply return a number, and
>>not an instance of the persistent class Product.java.  However, it seems
> 
> to
> 
>>me like every Query object must be passed a persistent class which is to
> 
> be
> 
>>populated.  In other words, the first parameter of every Query object
> 
> (e.g.
> 
>>QueryByCriteria, QueryBySQL, etc) has to be a persistent class.
>>
>>I have tried using Integer.class as the first parameter, but i receive a
>>ClassNotPersistenceCapableException.
>>
>>
>>Does anyone know how to handle such a simple request?
>>
>>Thanks for your help and time.
>>Ronen.
>>
>>
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> 
> 
> 
> 



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to