You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Lieven De Keyzer <li...@hotmail.com> on 2005/05/29 07:05:55 UTC

Update / subquery

This statement returns an SQLException, saying I got an error in my SQL 
query.
I can't seem to find one, so my question is: Is this possible in Ibatis?


<update id="updateAccount" parameterClass="account">
    UPDATE account
    SET email= #email#, first_name = #firstName#, last_name = #lastName#, 
password = #password#,  role_id = (SELECT role_id FROM role WHERE rolename = 
#role#)
    WHERE username = #username#
  </update>


  <resultMap id="accountResult" class="account">
    <result property="username" column="username"/>
    <result property="email" column="email"/>
    <result property="firstName" column="first_name"/>
    <result property="lastName" column="last_name"/>
    <result property="role" column="rolename"/>
    <result property="password" column="password"/>
    <result property="rootId" column="folder_id"/>
  </resultMap>

The error:
Cause: java.sql.SQLException: You have an error in your SQL syntax. Check 
the manual that corresponds to your MySQL server version for the right 
syntax to use near 'SELECT role_id FROM role WHERE rolename = 'admin')



Re: Struts and iBatis

Posted by Brandon Goodin <br...@gmail.com>.
I'm not really sure why you need a tutorial on Struts and iBatis.
iBatis is it's own product and should not depend on struts whatsoever.
I think your best bet is to read the ibatis documentation and the
iBatis Tutorial. I believe the Ricks tutorial is based on iBatis 1.x.
There is also the JPetstore 4 app that is based on struts. But it is
not a "standard" struts approach and may be a bit confusing. However,
the JPetStore 4 Struts takes an approach that modernizes the Struts
framework to be more like the new generation web frameworks like JSF.

http://ibatis.com/downloads.html

To give you a quick approach... The standard layerd approach is
Applications -> Service -> DAO. Application would be the layer that
would consist of Struts. The Service layer would consist of coarse
grained business logic and would contain NO knowledge of the
datasource. The DAO layer would consist of fine-grained calls to the
datasource and WOULD have knowledge of the datasource. The Service
Layer and the DAO layer should have their implementations hidden
behind interfaces. The common thread through all of these layers would
be your Domain/Model objects. The Domain objects can be seen as the
elements that each layer is concerned with. The Application Layer
displays and populates them as a result of user input. The Service
Layer operates on them as they pass through the path of your business
logic. The DAO layer transfers them to and from the datasource.

Hope that helps,
Brandon

On 5/29/05, Subbiah <su...@utdallas.edu> wrote:
> Hi,
> I have started working in Struts and planned to use Struts and iBatis. I
> actually studied Struts thru Reumann's site and when I was abt to use iBatis
> in my sample app, his site was down. I want to know
> 
> - if there are any good tutorials for iBatis and Struts.
> - Any idea when the site might be up
> 
> Thanks.
> regards,
> Subbiah
> 
>

Struts and iBatis

Posted by Subbiah <su...@utdallas.edu>.
Hi,
I have started working in Struts and planned to use Struts and iBatis. I
actually studied Struts thru Reumann's site and when I was abt to use iBatis
in my sample app, his site was down. I want to know 
 
- if there are any good tutorials for iBatis and Struts. 
- Any idea when the site might be up
 
Thanks.
regards,
Subbiah


Re: Update / subquery

Posted by Brandon Goodin <br...@gmail.com>.
I'm not sure why you posted the resultMap since you do not reference
it nor can you use it with an update statement. Your update statement
would function perfectly fine in ibatis assuming your paramters
satisfy the database. Your database is complaining that your SQL is
borked. Do you have logging enabled so that you can see what sql
statement is being passed and it's parameters?

Brandon

On 5/28/05, Lieven De Keyzer <li...@hotmail.com> wrote:
> This statement returns an SQLException, saying I got an error in my SQL
> query.
> I can't seem to find one, so my question is: Is this possible in Ibatis?
> 
> 
> <update id="updateAccount" parameterClass="account">
>     UPDATE account
>     SET email= #email#, first_name = #firstName#, last_name = #lastName#,
> password = #password#,  role_id = (SELECT role_id FROM role WHERE rolename =
> #role#)
>     WHERE username = #username#
>   </update>
> 
> 
>   <resultMap id="accountResult" class="account">
>     <result property="username" column="username"/>
>     <result property="email" column="email"/>
>     <result property="firstName" column="first_name"/>
>     <result property="lastName" column="last_name"/>
>     <result property="role" column="rolename"/>
>     <result property="password" column="password"/>
>     <result property="rootId" column="folder_id"/>
>   </resultMap>
> 
> The error:
> Cause: java.sql.SQLException: You have an error in your SQL syntax. Check
> the manual that corresponds to your MySQL server version for the right
> syntax to use near 'SELECT role_id FROM role WHERE rolename = 'admin')
> 
> 
>