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 Ashish Kulkarni <as...@gmail.com> on 2007/02/13 21:03:39 UTC

how to use ibatis to get data from multiple databases

Hi
I have a web application where i am using ibatis, i have a situation where i
want to select the database from where i want to get data.

In this application user will login and select he wants to use development
1, or development 2 or test 1 from a drop down

So if the user selects development1 i want to use database for development1
and so on.

But in ibatis i can define only one database in sqlMapConfig.

Also i can define multiple sqlMapConfig files (multiple xml files) one for
each database, but then in my servlets i will have to keep track of all the
sqlMapConfig

I want to be able to add these database at runtime.

Any ideas how we can do this

Ashish

Re: how to use ibatis to get data from multiple databases

Posted by Ashish Kulkarni <as...@gmail.com>.
Hi
Is there any source code for using properties when creating sql map client

Ashish

On 2/13/07, Larry Meadors <lm...@apache.org> wrote:
>
> Use a properties object when you create the sql map client.
>
> Larry
>
>
> On 2/13/07, Ashish Kulkarni <as...@gmail.com> wrote:
> > Hi
> > I have a web application where i am using ibatis, i have a situation
> where i
> > want to select the database from where i want to get data.
> >
> > In this application user will login and select he wants to use
> development
> > 1, or development 2 or test 1 from a drop down
> >
> > So if the user selects development1 i want to use database for
> development1
> > and so on.
> >
> > But in ibatis i can define only one database in sqlMapConfig.
> >
> > Also i can define multiple sqlMapConfig files (multiple xml files) one
> for
> > each database, but then in my servlets i will have to keep track of all
> the
> > sqlMapConfig
> >
> > I want to be able to add these database at runtime.
> >
> > Any ideas how we can do this
> >
> > Ashish
> >
>

Re: how to use ibatis to get data from multiple databases

Posted by Jonathan Chase <jc...@gmail.com>.
Although this would require the use of the Spring Framework, it provides a
pretty transparent way to do what you're asking:

http://blog.interface21.com/main/2007/01/23/dynamic-datasource-routing/

You could probably adapt the idea pretty easily and get rid of the Spring
dependencies if that is an issue.

Jon


On 2/13/07, Larry Meadors <lm...@apache.org> wrote:
>
> Use a properties object when you create the sql map client.
>
> Larry
>
>
> On 2/13/07, Ashish Kulkarni <as...@gmail.com> wrote:
> > Hi
> > I have a web application where i am using ibatis, i have a situation
> where i
> > want to select the database from where i want to get data.
> >
> > In this application user will login and select he wants to use
> development
> > 1, or development 2 or test 1 from a drop down
> >
> > So if the user selects development1 i want to use database for
> development1
> > and so on.
> >
> > But in ibatis i can define only one database in sqlMapConfig.
> >
> > Also i can define multiple sqlMapConfig files (multiple xml files) one
> for
> > each database, but then in my servlets i will have to keep track of all
> the
> > sqlMapConfig
> >
> > I want to be able to add these database at runtime.
> >
> > Any ideas how we can do this
> >
> > Ashish
> >
>

Re: how to use ibatis to get data from multiple databases

Posted by Larry Meadors <lm...@apache.org>.
Use a properties object when you create the sql map client.

Larry


On 2/13/07, Ashish Kulkarni <as...@gmail.com> wrote:
> Hi
> I have a web application where i am using ibatis, i have a situation where i
> want to select the database from where i want to get data.
>
> In this application user will login and select he wants to use development
> 1, or development 2 or test 1 from a drop down
>
> So if the user selects development1 i want to use database for development1
> and so on.
>
> But in ibatis i can define only one database in sqlMapConfig.
>
> Also i can define multiple sqlMapConfig files (multiple xml files) one for
> each database, but then in my servlets i will have to keep track of all the
> sqlMapConfig
>
> I want to be able to add these database at runtime.
>
> Any ideas how we can do this
>
> Ashish
>