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 jesid <ja...@gmail.com> on 2008/08/22 01:17:11 UTC

mutiple parameters in query

I need know how send the parameters to query if the query have more than 1
table, for example:

<select id="getCar" resultClass="co.enti.Car">
   SELECT
       car.COD_CAR as cod,
       per.NAME as name
   FROM
       IPS_CARA car,
       IPS_PERSON per
   WHERE
       car.COD_CAR = #cod# AND
       per.NAME like '%$name$%'
</select>


I´m sending the parameters this way



Car car = (Car) sqlMap.queryForObject("getCar", ???????);   ---- > here is
that I need help


and the bean from the table IPS_CARA, Car is for example:

public class Car {
     private String model;
   private int cod;
   private int codPer;

   public int getCodPer() {
       return codPer;
   }
   public void setCodPer(int codPer) {
       this.codPer = codPer;
   }

   public int getCod() {
       return cod;
   }
   public void setCod(int cod) {
       this.cod = cod;
   }

   public int getModel() {
       return model;
   }
   public void setModel(int model) {
       this.model = model;
   }

}

and IPS_PERSON is

public class Person {
     private String name;
   private String lastName;
   private int codPer;

   public int getCodPer() {
       return codPer;
   }
   public void setCodPer(int codPer) {
       this.codPer = codPer;
   }

   public String getName() {
       return cod;
   }
   public void setName(String name) {
       this.name = name;
   }

   public String getLastName() {
       return lastName;
   }
   public void setLastName(String lastName) {
       this.lastName = lastName;
   }

}

thank....:handshake:
-- 
View this message in context: http://www.nabble.com/mutiple-parameters-in-query-tp19098786p19098786.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: mutiple parameters in query

Posted by jesid <ja...@gmail.com>.
I found the answer and it is this :clap:

List result = sqlMap.queryForList("twoTables", params);


and the xml

<resultMap id="paramTable" class="hashmap">
	<result property="cod" column="COD"/>
	<result property="default" column="DEF"/>
	<result property="codeCar" column="COD_CAR"/>
	<result property="name" column="NAME"/>
</resultMap>

<select id="twoTables" resultClass="hashmap" resultMap="paramTable">
	SELECT 
	        *
	FROM 
	        IPS_CARA car,
	        IPS_PERSON per
	WHERE
	        car.COD_CAR = per.COD_CAR and
	        car.COD = #codeCar#
</select>


thus returns a list filled with hasMap containing all objects.

Good luck
-- 
View this message in context: http://www.nabble.com/mutiple-parameters-in-query-tp19098786p19108786.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: mutiple parameters in query

Posted by Jonathan Slate <js...@mtl.mit.edu>.
Hi jesid:

I'm not sure exactly why you want to do this, the idea is that one 
statement gives you one object. I don't even use the map stuff much b/c 
the whole point it that it is object oriented, you can easily populate 
your business objects from the DB. I suppose you could get a map of all 
the columns from both tables then go through the trouble of setting the 
values of each object from the map, but then why bother with iBATIS at all?

If, on the other hand, one of the objects is a member field of the 
other, then there are certainly ways to handle that, you'd want to look 
at the manual again for that. (One option is <result...select="..." /> 
in your resultMap element.) Hope this helps.

-Jonathan


jesid wrote:
> Hi larry, yes I read the user's guide but the problem is the follow:
>
> I need know, how can i get the result from query of two or more tables? for
> example, IPS_CARA, IPS_PERSON, this tables return to me two object
> diferents.
>
> I´m doing thus:
>
>
> Map resultMap = (HashMap) sqlMap.queryForMap("getTwoTablas",paramsMap,
> "nameKey");
>
>
> ----------
>
> <select id="getTwoTablas" resultClass="hashmap">
> SELECT 
>         *
> FROM 
> 	IPS_CARA car,
> 	IPS_PERSON per
> WHERE
> 	car.COD = per.COD and
> 	car.COD = #cod#
> </select>
>
>
> in this way the resultMap only contains 1 object, being that the query
> return more than 1 object and the key from map is null ("nameKey").
>   

Re: mutiple parameters in query

Posted by jesid <ja...@gmail.com>.
Hi larry, yes I read the user's guide but the problem is the follow:

I need know, how can i get the result from query of two or more tables? for
example, IPS_CARA, IPS_PERSON, this tables return to me two object
diferents.

I´m doing thus:


Map resultMap = (HashMap) sqlMap.queryForMap("getTwoTablas",paramsMap,
"nameKey");


----------

<select id="getTwoTablas" resultClass="hashmap">
SELECT 
        *
FROM 
	IPS_CARA car,
	IPS_PERSON per
WHERE
	car.COD = per.COD and
	car.COD = #cod#
</select>


in this way the resultMap only contains 1 object, being that the query
return more than 1 object and the key from map is null ("nameKey").
-- 
View this message in context: http://www.nabble.com/mutiple-parameters-in-query-tp19098786p19108178.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: mutiple parameters in query

Posted by Larry Meadors <la...@gmail.com>.
Did you even glance at the user's guide?

Please take a quick peek at it - in 5 minutes, it'll answer all of the
questions you've asked...in 5 languages.

http://ibatis.apache.org/javadownloads.cgi

Really. :)

Larry

RE: mutiple parameters in query

Posted by jesid <ja...@gmail.com>.
hi Eric very thank for you help, i can solve the problem with what you told
me :clap:. But i have another another problem and is how can i get the
result from query of two or more tables?
-- 
View this message in context: http://www.nabble.com/mutiple-parameters-in-query-tp19098786p19107133.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


RE: mutiple parameters in query

Posted by "Givler, Eric" <eg...@state.pa.us>.
Try adding parameterClass="map" in the ibatis mapping.
In the calling code, add:

Map params = new HashMap();
map.put("cod", codeParameterValue );
map.put("name", nameParameterValue );
Car car = (Car) sqlMap.queryForObject("getCar", params );

Let me know how this works out since I'm not at work to test this.
Eric
________________________________________
From: jesid [javav112@gmail.com]
Sent: Thursday, August 21, 2008 7:17 PM
To: user-java@ibatis.apache.org
Subject: mutiple parameters in query

I need know how send the parameters to query if the query have more than 1
table, for example:

<select id="getCar" resultClass="co.enti.Car">
   SELECT
       car.COD_CAR as cod,
       per.NAME as name
   FROM
       IPS_CARA car,
       IPS_PERSON per
   WHERE
       car.COD_CAR = #cod# AND
       per.NAME like '%$name$%'
</select>


I´m sending the parameters this way



Car car = (Car) sqlMap.queryForObject("getCar", ???????);   ---- > here is
that I need help


and the bean from the table IPS_CARA, Car is for example:

public class Car {
     private String model;
   private int cod;
   private int codPer;

   public int getCodPer() {
       return codPer;
   }
   public void setCodPer(int codPer) {
       this.codPer = codPer;
   }

   public int getCod() {
       return cod;
   }
   public void setCod(int cod) {
       this.cod = cod;
   }

   public int getModel() {
       return model;
   }
   public void setModel(int model) {
       this.model = model;
   }

}

and IPS_PERSON is

public class Person {
     private String name;
   private String lastName;
   private int codPer;

   public int getCodPer() {
       return codPer;
   }
   public void setCodPer(int codPer) {
       this.codPer = codPer;
   }

   public String getName() {
       return cod;
   }
   public void setName(String name) {
       this.name = name;
   }

   public String getLastName() {
       return lastName;
   }
   public void setLastName(String lastName) {
       this.lastName = lastName;
   }

}

thank....:handshake:
--
View this message in context: http://www.nabble.com/mutiple-parameters-in-query-tp19098786p19098786.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.