Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

JDBC and changing database systems

Options
  • 27-10-2001 4:32am
    #1
    Closed Accounts Posts: 219 ✭✭


    Hi folks,

    To what extent does using JDBC to talk to my database abstract me from the workings of the database system? Is moving from something like an Access database to Oracle or MySQL simply a matter of changing a driver or is it more involved?

    Bosco


Comments

  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    In theory, if you write your code correctly, you move your database to a new platform, swap over the connection, and all is well.

    In practice, you will find that you write your SQL for the DB platform youre using. For example, a join in Oracle is vastly differently structured to a join in MSSQL.

    In theory, you can write JDBC-compliant statements, and JDBC will do all the translations for you, but in practice this doesnt usually happen.

    Also bear in mind that not all databases support the same set of functionality or even datatypes, so you may find that not only does the SQL need to be different, but you may need different approaches on different systems.

    The most common solution I've seen is to end up writing "data factories" and "data access classes". For each DB system, you implement a new data-access class. Your app asks the factory to create the class, and it does so based on some configuration parameter (ini file or whatever) which tells it which db to support right now.

    So you end up with :


    Business Class ..... (Data Factory) ..... DataAccessClass
    (implements DACInterface)


    your business class has all the business logic (surprise), and when it needs to work with the database, it gets a data access class from teh factory, and all the various class implementations share a common interface, so you dont need special code in the Business class.

    Hope this makes sense.

    jc


  • Closed Accounts Posts: 219 ✭✭Bosco


    Hiya Bonkey....thanks for replying,

    I understand most, but not all of what I need to do. I understand the reasons for dividing the system into different layers (business & data access) but not how to implement it. This concept of a 'data factory' for example is a mystery to me.

    Where should I look for information about this kind of thing? (i.e. how do design my system as opposed to how to code it)

    Bosco


  • Closed Accounts Posts: 219 ✭✭Bosco


    Says me - Where should I look for information about this kind of thing? (i.e. how do design my system as opposed to how to code it)

    That doesn't really make sense does it :rolleyes: I suppose books on this kind of thing are always written with a particular programming language/technology in mind.

    I guess what I'm really asking is will a JDBC tutorial on the net teach me all I need to know or will I have to buy some kind of 'Enterprise Architectures in Java' book? Where did you learn what you know about these things bonkey?

    Thanks folks,

    Bosco


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by Bosco
    I guess what I'm really asking is will a JDBC tutorial on the net teach me all I need to know or will I have to buy some kind of 'Enterprise Architectures in Java' book? Where did you learn what you know about these things bonkey?

    I learned from a number of places....books, other people's code, other people's ideas, 10 years of coding experience, blah blah blah.

    IIRC, I saw the data-factory stuff properly implemented in Suns "blueprints" docs up on their site. OK - they do it in relation to bean-managed-persistence with EJBs, but thats neither here nor there....the basic principle is the same. I can dig up a URL if you cant find it yourself.

    To give you an idea of what I mean by a data factory...

    I have my "business class". It needs to talk to the database. It therefore instantiates a "data-access-class". However, if I want to have support for 6 different databases, then I might need 6 different implementations of the DAC. How do I reslove this?

    Simple...

    Each of the DAC implementations uses a common interface which I'll call iDAC). If you know about OO, you'll know that this means that the business class can treat any DAC as an object of type iDAC.

    Now - when I want to create the DAC, I need to know which type of one I want! So....get your business class to call what is known as a factory class. This guy reads your app's config file and says "Ah - Bosco is using Oracle today. Right - Oracle DAC coming up". It then creates an oracleDAC, but returns it as an iDAC if you see what I mean?

    So - the business class simply asks for an iDAC, and gets back one which supports the database which the app is configured for. Adding new database support then simply involves writing a new DAC (again, implementing the iDAC interface) and making a small change to the "factory" class to cater for this new type.

    Hopw that makes a bit of sense.

    jc


  • Closed Accounts Posts: 219 ✭✭Bosco


    Thanks Bonkey. It does make a good deal of sense, though it drives home to me how much I have yet to learn if I'm going to get this project done in time....why oh why did I have to pick a programming project.... :)


  • Advertisement
  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    Here's a good site for information on the Factory pattern.

    http://www.patterndepot.com/put/8/JavaPatterns.htm

    Take a look at the Creational Patterns for information on Factories.

    There's quite a lot of the book there, but it's worth buying the actual thing if you're interested.


  • Closed Accounts Posts: 219 ✭✭Bosco


    Hi folks,

    I actually have Design Patterns. I bought it when I started learning to program (properly) but I have yet to learn enough about OO progamming to understand the book fully :) Soon....

    Bonkey.....I've heard I can use an XML file stored on my web/app server as a kind of database. Will it be possible to write a data access class to talk to the XML file, and have it implement the same interface as a data access class for a database system?

    Bosco


  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    I think I read somewhere recently (possibly xml.com) that someone's writing a kind of query language or API for XML.
    However XML is not a DBMS nor was it ever meant to be a DBMS, it just describes data.

    That said XML is just fine as a field in a DBMS.


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by Bosco
    Bonkey.....I've heard I can use an XML file stored on my web/app server as a kind of database. Will it be possible to write a data access class to talk to the XML file, and have it implement the same interface as a data access class for a database system?
    Heh - of course it is :) Just as long as you design your XML well....

    Enygma....you're talking about XQL I think. Interesting stuff, but in very early stages yet.

    jc


  • Closed Accounts Posts: 219 ✭✭Bosco


    Hi folks,

    I realise an XML file is no replacement for the DBMS. However, from what I understand of it, I think it can help me speed up certain aspects of my system and greatly reduce the number of concurrent DB acceses (which may be very important to me if I have to use Access) when the system is under load, by using the XML file as a kind of easy-to-implement read cache (for data that doesn't need to be secured).

    What is the XML equivalent of JDBC in Java? (i.e. what else am I going to have to learn in order to use XML as a data source)

    Bosco

    BTW Thanks for this help guys, it makes a world of difference :)


  • Advertisement
  • Registered Users Posts: 16,413 ✭✭✭✭Trojan


    Slightly OT: Software AG[1] have a database called Tamino which stores in native XML format. It was the first db to do that.

    I'm not an app guy, so I nothing about this (specially db stuff): what dbs store in XML native now?

    Other thing I've to start doing is storing my own docs as XML & parsing out the txt and html as needed. (Has anyone read "The Pragmatic Programmer"? ) Anyone who's doing their internal docs this way post up what & how you're doing, please. Here's a /. article, some good info in there: http://slashdot.org/article.pl?sid=01/09/06/042226

    Al.

    1. (I used to work there) ... they call themselves "The XML company" :)http://www.softwareag.com/


  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    Hi Trojan,
    I've actually started something like that in work.
    Our software uses a fairly extensive tag library and what I've done is created a DTD for describing a Tag. I'm thinking most of this kind of stuff can be taken from the TLD anyways but I digress.
    We're using XSL to render the tags to HTML and PDF and our own software to cross-reference tags and link to the relevant Javadocs. That's about as much as I can say really I guess, wouldn't want to be giving away any secrets now :p

    It'd be cool if Javadoc was created as XML then you could render it whichever way you wanted.

    Here's an article (I actually mentioned it on another thread in here wrt XQuery) about NXD's (yes, they've already got their own TLA :) XML people love that don't they?)

    http://www.xml.com/pub/a/2001/10/31/nativexmldb.html


    I think a fella I went to college with worked in "The XML Company" for a month or something, then he got a job where I am now. You remember a guy called Eugene? This was over a year ago now. (Their site seems to be down too)


Advertisement