multiple/any Database-Module with jdbc

Discussion in 'Java' started by gert, Mar 12, 2007.

  1. gert

    gert Guest

    Hey,

    i want to use in my application any database, example hsql, mysql,
    oracle, etc. . For the specified database-connection i think to write
    modules. Have anybody samples or tricks for developing the function/
    modules?
    How registered itself the module on a application?


    Thanks.

    gp
     
    gert, Mar 12, 2007
    #1
    1. Advertising

  2. gert

    ck Guest

    On Mar 13, 12:49 am, "gert" <> wrote:
    > Hey,
    >
    > i want to use in my application any database, example hsql, mysql,
    > oracle, etc. . For the specified database-connection i think to write
    > modules. Have anybody samples or tricks for developing the function/
    > modules?
    > How registered itself the module on a application?
    >
    > Thanks.
    >
    > gp


    Are you aware about hibernate? http://www.hibernate.org

    --
    Ck
     
    ck, Mar 12, 2007
    #2
    1. Advertising

  3. gert

    ck Guest

    On Mar 13, 12:49 am, "gert" <> wrote:
    > Hey,
    >
    > i want to use in my application any database, example hsql, mysql,
    > oracle, etc. . For the specified database-connection i think to write
    > modules. Have anybody samples or tricks for developing the function/
    > modules?
    > How registered itself the module on a application?
    >
    > Thanks.
    >
    > gp


    Are you aware about hibernate? http://www.hibernate.org

    --
    Ck
     
    ck, Mar 12, 2007
    #3
  4. gert

    Lew Guest

    "gert" <> wrote:
    >> i want to use in my application any database, example hsql, mysql,
    >> oracle, etc. . For the specified database-connection i think to write
    >> modules. Have anybody samples or tricks for developing the function/
    >> modules?
    >> How registered itself the module on a application?


    Use JDBC, at least. (Frameworks that sit atop JDBC are a trivial extension of
    the idea.)

    Your code that uses JDBC will not change with different databases.

    Put the database Driver class name and connection strings in a property file
    and load the properties at program startup.

    For a JDBC driver class name stored in a String variable "driver" you
    "register ... the module" by

    Class.forName( driver );

    which loads the driver class and registers it with the DriverManager.

    Check out the tutorials on JDBC.

    -- Lew
     
    Lew, Mar 12, 2007
    #4
  5. Lew wrote:
    > "gert" <> wrote:
    >>> i want to use in my application any database, example hsql, mysql,
    >>> oracle, etc. . For the specified database-connection i think to write
    >>> modules. Have anybody samples or tricks for developing the function/
    >>> modules?
    >>> How registered itself the module on a application?

    >
    > Use JDBC, at least. (Frameworks that sit atop JDBC are a trivial
    > extension of the idea.)


    It is rather difficult to write database code in Java that does not
    use JDBC.

    :)

    > Your code that uses JDBC will not change with different databases.


    That is the goal. It is even possible for simple database
    usage. But for more advanced database usages it often becomes
    very difficult.

    As soon as you need something non standard SQL then it
    becomes tricky.

    Arne
     
    =?UTF-8?B?QXJuZSBWYWpow7hq?=, Mar 13, 2007
    #5
  6. gert

    gert Guest

    Hello Lew,

    > "gert" <> wrote:
    > >> i want to use in my application any database, example hsql, mysql,
    > >> oracle, etc. . For the specified database-connection i think to write
    > >> modules. Have anybody samples or tricks for developing the function/
    > >> modules?
    > >> How registered itself the module on a application?

    >
    > Use JDBC, at least. (Frameworks that sit atop JDBC are a trivial extension of
    > the idea.)
    >
    > Your code that uses JDBC will not change with different databases.


    yest i use it early.

    > Put the database Driver class name and connection strings in a property file
    > and load the properties at program startup.
    >
    > For a JDBC driver class name stored in a String variable "driver" you
    > "register ... the module" by
    > Class.forName( driver );


    ok, i have it so. I meant how does load the program the properties/
    module at startup? How make it neatbeans to example? Read/scan the
    program a directory where the modules there are?

    i'm on the right way. :)


    regards

    gp
     
    gert, Mar 13, 2007
    #6
  7. gert

    Lew Guest

    gert wrote:
    > ok, i have it so. I meant how does load the program the properties/
    > module at startup? How make it neatbeans to example? Read/scan the
    > program a directory where the modules there are?


    Use Properties files.

    During initialization of the module load the JDBC driver using the property
    for the DB driver that you define in your Properties file. Connect to the
    database using properties defined in your Properties.

    You will find what you need to know in the API docs for java.util.Properties.

    -- Lew
     
    Lew, Mar 13, 2007
    #7
  8. gert

    ck Guest

    On Mar 13, 6:20 pm, Lew <> wrote:
    > gert wrote:
    > > ok, i have it so. I meant how does load the program the properties/
    > > module at startup? How make it neatbeans to example? Read/scan the
    > > program a directory where the modules there are?

    >
    > Use Properties files.
    >
    > During initialization of the module load the JDBC driver using the property
    > for the DB driver that you define in your Properties file. Connect to the
    > database using properties defined in your Properties.
    >
    > You will find what you need to know in the API docs for java.util.Properties.
    >
    > -- Lew


    In case you are planning to use Properties, you would need to put the
    database queries and DML as well in the Properties file. In some
    situations the DML and queries can be Database specific. Hence if they
    are hard coded in the class you would need to do something about it.

    --
    Ck
    http://www.gfour.net
     
    ck, Mar 13, 2007
    #8
  9. gert

    Lew Guest

    ck wrote:
    > In case you are planning to use Properties, you would need to put the
    > database queries and DML as well in the Properties file. In some
    > situations the DML and queries can be Database specific. Hence if they
    > are hard coded in the class you would need to do something about it.


    Need to? No. Want to? Maybe, but I doubt it.

    How many projects have you ever been on that changed DMBSes?

    Why in the world would you use DBMS-specific constructs if you are ever
    planning to change DBMSes? Use vanilla SQL and put the tricky stuff in the
    Java code.

    Consider if you had such a properties file. It could be massive, incredibly
    hard to debug, and just as difficult to change as code if you did switch back
    ends. The code that used those SQL statements would be segregated from the
    logic that it implements and thus much harder to debug and maintain.

    If the code is in well-designed DAO-layer classes, then the effort of changing
    the SQL is the same if you change back ends, but maintenance and debugging for
    the much more usual case of not changing DMBSes is much, much easier. Locality
    of reference applies to the mind, not just memory chips and caches.

    Keep the SQL with the Java code that uses it, not in a properties file.

    -- Lew
     
    Lew, Mar 14, 2007
    #9
  10. gert

    ck Guest

    On Mar 14, 10:01 am, Lew <> wrote:
    > ck wrote:
    > > In case you are planning to use Properties, you would need to put the
    > > database queries and DML as well in the Properties file. In some
    > > situations the DML and queries can be Database specific. Hence if they
    > > are hard coded in the class you would need to do something about it.

    >
    > Need to? No. Want to? Maybe, but I doubt it.
    >
    > How many projects have you ever been on that changed DMBSes?


    If that was the situation then this question would have not existed in
    the first place.

    > Why in the world would you use DBMS-specific constructs if you are ever
    > planning to change DBMSes? Use vanilla SQL and put the tricky stuff in the
    > Java code.


    > [Clipped]


    May be using properties file is a bad idea but what I wanted to convey
    was that -

    There are lot of DB specific features, which developer might use to
    develop the application(initially), later when you have to migrate to
    someother DB its a problem. For that matter Databases don't follow any
    standard for DML or Queries, in my opinion Oracle is a leader at
    breaking the standards set.

    Ck
    http://www.gfour.net
     
    ck, Mar 14, 2007
    #10
  11. gert

    Lew Guest

    ck wrote:
    > in my opinion Oracle is a leader at breaking the standards set.


    MySQL and MS Access have Oracle way beat.

    -- Lew
     
    Lew, Mar 14, 2007
    #11
  12. Lew wrote:
    > ck wrote:
    >> In case you are planning to use Properties, you would need to put the
    >> database queries and DML as well in the Properties file. In some
    >> situations the DML and queries can be Database specific. Hence if they
    >> are hard coded in the class you would need to do something about it.

    >
    > Need to? No. Want to? Maybe, but I doubt it.
    >
    > How many projects have you ever been on that changed DMBSes?


    Ever head about "products" that needs to support many databases.

    > Why in the world would you use DBMS-specific constructs if you are ever
    > planning to change DBMSes? Use vanilla SQL and put the tricky stuff in
    > the Java code.


    Sometimes you need database specific features.

    Try think about why most persistence frameworks require
    you to specific the SQL dialect.

    > Consider if you had such a properties file. It could be massive,
    > incredibly hard to debug, and just as difficult to change as code if you
    > did switch back ends. The code that used those SQL statements would be
    > segregated from the logic that it implements and thus much harder to
    > debug and maintain.


    You may be right.

    But non the less the use of putting critical information in
    config files is rather widely used in Java - from EJB's to
    Hibernate to Spring.

    Arne
     
    =?UTF-8?B?QXJuZSBWYWpow7hq?=, Mar 14, 2007
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Keith Wansbrough

    Re: jdbc help:sun.jdbc.odbc.JdbcOdbcDriver

    Keith Wansbrough, Aug 16, 2004, in forum: Java
    Replies:
    0
    Views:
    783
    Keith Wansbrough
    Aug 16, 2004
  2. Betty
    Replies:
    1
    Views:
    9,905
    Juha Laiho
    May 21, 2005
  3. Jesus M. Salvo Jr.
    Replies:
    2
    Views:
    4,306
    robert
    Feb 11, 2006
  4. Bruce
    Replies:
    4
    Views:
    780
    Bjorn Abelli
    Mar 25, 2006
  5. kevin Liu
    Replies:
    19
    Views:
    722
    Firefox 32
    Oct 7, 2008
Loading...

Share This Page