SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Zealot waji's Avatar
    Join Date
    Dec 2004
    Location
    United Kingdom
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Single Query for Multiple Databases using JSP

    Hello,

    I just want to know, that is it possible, to use a single Query for Multiple databases using JSP?

    for example
    I have two databases, Database1 and Database2
    and I want to search something by single query in both databases?

    If yes, is it possible with Ms Access databases?
    need help thanks and will appreciate any tutorial related to it,


    Thanks and Regards

  2. #2
    SitePoint Zealot waji's Avatar
    Join Date
    Dec 2004
    Location
    United Kingdom
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,
    I dont know why, this post haven't recieved any reply,
    hmm, m waiting

    Support is highly appreciated

    Thanks

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,336
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by waji View Post
    I dont know why, this post haven't recieved any reply
    possibly because not enough information is provided

    which tables in the two databases? can you describe the tables? are they related in some way? what query are you planning to run on them?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Zealot waji's Avatar
    Join Date
    Dec 2004
    Location
    United Kingdom
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the reply,
    just for example, i want to SELECT something from Table1 in DB1 and DB2;
    my point is, is it possible in JSP envirnoment?

    thanks

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,336
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    what do you want to select? what does table1 look like (what columns)? does table1 exist in both databases? if not, what does table2 look like? how are they related?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  6. #6
    SitePoint Zealot waji's Avatar
    Join Date
    Dec 2004
    Location
    United Kingdom
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    what do you want to select? what does table1 look like (what columns)? does table1 exist in both databases? if not, what does table2 look like? how are they related?
    if you put all these questions aside,
    First of all; I want to know, is it possible in JSP envirnoment?
    my question is JSP oriented, becuase, I know how to achieve rest of the things!

    thanks for your participation.
    Regards

  7. #7
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As I know all languages use a connection to a database.
    As there are 2 database how can you use 1 connection for 2 different databases?Is there a way?
    You may use Objects or something as arraylist to put the things that you want from the databases together.

  8. #8
    SitePoint Zealot waji's Avatar
    Join Date
    Dec 2004
    Location
    United Kingdom
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dimis283 View Post
    As I know all languages use a connection to a database.
    As there are 2 database how can you use 1 connection for 2 different databases?Is there a way?
    same as I think, that how we can achieve this goal by single connection? or what really we need to do, to run single query for two databases?

  9. #9
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As I know there are memory databases, that means that they are at RAM .So one Idea is to create a database like that with h2 database for example or a simiral small database and to put there the tables.
    But there must be a problem of memory and performance (if also there are many records).
    An idea is to make a database and put there all the records that you want once per day, it is possible?

  10. #10
    SitePoint Addict dAEk's Avatar
    Join Date
    Oct 2003
    Location
    Stockholm, Sweden
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by waji View Post
    same as I think, that how we can achieve this goal by single connection? or what really we need to do, to run single query for two databases?
    You will need two connection objects to do what you want to achieve here. This is because statements (incl. perparedStatements) are connected to the connection object which specify what database to connect to. So unfortunately I don't think you can without making changes to the Java code.
    Last edited by dAEk; Jan 5, 2008 at 04:22. Reason: Corrected a typo.
    David Shamloo-Ekblad

    Go Habs! | For music addicts: Last.fm, SongMeanings

  11. #11
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,336
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    or search in one database and then search in the other database and combine the results yourself

    any chance you could provide more information on what you're actually trying to achieve?

    for instance, why does it have to be one query? how are the tables related?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  12. #12
    SitePoint Wizard
    Join Date
    Apr 2007
    Posts
    1,401
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    First, I'm not sure why you would want to code that logic in JSP but anyways. Short answer is YES!!!

    Good solution would be to use EJB 3.0 Entity bean, you don't need J2EE server to use Entity bean, so tomcat alike servers work and I've implemented many times.

    I won't go into too much detail but EJB 3.0 EB has their own query language called "EJBQL" which works on any database vendor that EJB 3.0 supports (probably ms access)

    Then there's something called EntityManager, which is a class that connects to a specific database server. So, you'll have 2 types of EntityManager.

    Anyways, trying to post how to use EJB 3.0 entity bean on a single post is nearly impossible. I'm sure you'll find a lot of resource through google!

    P.S. I'm sure you know but putting business logic in JSP is not a good practice.

  13. #13
    SitePoint Zealot
    Join Date
    Aug 2007
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by waji View Post
    Hello,

    I just want to know, that is it possible, to use a single Query for Multiple databases using JSP?

    for example
    I have two databases, Database1 and Database2
    and I want to search something by single query in both databases?

    If yes, is it possible with Ms Access databases?
    need help thanks and will appreciate any tutorial related to it,


    Thanks and Regards
    I would say use "Database Links" in the Db and use same in your Query.
    I am familiar with Oracle and yes it is possible with that..but MSAcess i am not sure

  14. #14
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you use access, It does...link
    You really want to use ms access with java, have you a jdbc driver?
    You may look at h2, put at "search" linked table, I just find the solution.
    I think this must be one of the solutions.

  15. #15
    SitePoint Wizard
    Join Date
    Apr 2007
    Posts
    1,401
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hibernate is one of JPA provider. All I can say is check out this link
    http://www.hibernate.org/80.html


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •