Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > multiple/any Database-Module with jdbc

Reply
Thread Tools

multiple/any Database-Module with jdbc

 
 
gert
Guest
Posts: n/a
 
      03-12-2007
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

 
Reply With Quote
 
 
 
 
ck
Guest
Posts: n/a
 
      03-12-2007
On Mar 13, 12:49 am, "gert" <gert.pin...@web.de> 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

 
Reply With Quote
 
 
 
 
ck
Guest
Posts: n/a
 
      03-12-2007
On Mar 13, 12:49 am, "gert" <gert.pin...@web.de> 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

 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      03-12-2007
"gert" <gert.pin...@web.de> 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
 
Reply With Quote
 
=?UTF-8?B?QXJuZSBWYWpow7hq?=
Guest
Posts: n/a
 
      03-13-2007
Lew wrote:
> "gert" <gert.pin...@web.de> 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

 
Reply With Quote
 
gert
Guest
Posts: n/a
 
      03-13-2007
Hello Lew,

> "gert" <gert.pin...@web.de> 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




 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      03-13-2007
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
 
Reply With Quote
 
ck
Guest
Posts: n/a
 
      03-13-2007
On Mar 13, 6:20 pm, Lew <l...@nospam.lewscanon.com> 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

 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      03-14-2007
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
 
Reply With Quote
 
ck
Guest
Posts: n/a
 
      03-14-2007
On Mar 14, 10:01 am, Lew <l...@nospam.lewscanon.com> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: [JDBC] JDBC Driver and timezones Lew Java 0 05-19-2010 03:33 PM
How to parse the jdbc driver name from the jdbc .jar file Bruce Java 4 03-25-2006 12:01 PM
stand-alone JMS, other JDBC operations, and transactions ( ActiveMQ + JOTM + JDBC operations ) Jesus M. Salvo Jr. Java 2 02-11-2006 06:33 PM
oracle.jdbc.OracleDriver vs oracle.jdbc.driver.OracleDriver Betty Java 1 05-21-2005 05:15 PM
Re: jdbc help:sun.jdbc.odbc.JdbcOdbcDriver Keith Wansbrough Java 0 08-16-2004 07:31 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57