Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.databases > #618

Re: Local database library

From Kevin Nathan <knathan@project54.com>
Newsgroups comp.lang.java.databases
Subject Re: Local database library
Date 2013-10-01 15:41 -0700
Message-ID <20131001154157.7f37e588@efreet.linux> (permalink)
References <20131001135230.66af12f9@efreet.linux> <524b40ba$0$304$14726298@news.sunsite.dk>

Show all headers | View raw


On Tue, 01 Oct 2013 17:38:01 -0400
Arne Vajhøj <arne@vajhoej.dk> wrote:

>On 10/1/2013 4:52 PM, Kevin Nathan wrote:
>> I'm a Java newbie, but have been programming for many years. I'm
>> converting an existing application from C++ to Java. In an effort to
>> clean it up a bit, I would like to build a local library of database
>> access routines because right now everyone does their own connecting
>> and SQL writing, with way too much duplication.
>
>Create one or more classes that in more or less OOP style encapsulate
>the JDBC code.
>
>That should not be much different between Java and C++.
>

It's not, and that is what I am doing now, but at present it needs to
be copied into source files (at least, that's what the other
developers have done -- I'm trying to find a better way). I am more
interested in learning about the file structure I would use for a
library. I think I have it started, but a tutorial on building a
library from scratch would be advantageous at this point. It's a lot of
trial and error right now from the little bit of info I have found on
the internet.


>Often in Java you would not use JDBC and SQL but instead an ORM,
>given a time crunch that may not be an option for you even if the
>task at hand leaned towards it (and that is not give since you
>did not specify what you are working on).
>

I am a self-taught programmer and have never been involved with an ORM
so that's another whole level of instruction I will need! :-) I am
using NetBeans and that is helping a bit. But again, a tutorial on
building a Java library would be the best. This is the best I've found
on that, so far:

http://stackoverflow.com/questions/6205483/creating-accessing-libraries-in-netbeans

which is why I am still doing a lot of trial and error.

We have about 30 tables in the database (for livestock auction markets)
and I want to be able to just call a function from the main programs to
get the data, like: 

  getTransData()
  getBuyerData()...

instead of having this in the main file:

try {
    Statement st = (Statement) con.createStatement();
    String command =
    "SELECT "
      + "SELLERID, HEAD, DESCRIP, "
      + "ROUND(WEIGHT/HEAD) AS AVG_WGT, "
      + "WEIGHT, BUYERID, PRICE, BUYERPEN, "
      + "(SELECT name FROM seller "
      + "WHERE date=(SELECT MAX(start) FROM sales WHERE sel=1) "
      + "AND number=trans.sellerid) AS NAME, "
      + "(SELECT GROUP_CONCAT(tag_num) FROM backtags "
      + "WHERE trans_id=trans.trans_id and ckin_date="
      + "(SELECT MAX(start) FROM sales WHERE sel=1) 
      + "GROUP BY trans_id) AS ALLTAGS "
      + "FROM trans "
      + "WHERE TRANS_ID = '" + transNum + "' "
      + "AND date=(SELECT MAX(start) FROM sales WHERE sel=1)";
    ResultSet rs = st.executeQuery(command); 
} else {
    return;
}

So, I know what I *want* to do, just not the best way to do it in Java.
If that makes any sense.


-- 
Kevin Nathan (Arizona, USA)  
Linux is not a destination, it's a journey -- enjoy the trip!

Linux 3.7.10-1.16-desktop
 15:19pm  up 13 days  1:32,  14 users,  load average: 0.59, 0.51, 0.48

Back to comp.lang.java.databases | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Local database library Kevin Nathan <knathan@project54.com> - 2013-10-01 13:52 -0700
  Re: Local database library Arne Vajhøj <arne@vajhoej.dk> - 2013-10-01 17:38 -0400
    Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-01 15:41 -0700
      Re: Local database library Arne Vajhøj <arne@vajhoej.dk> - 2013-10-01 20:53 -0400
        Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-02 10:09 -0700
          Re: Local database library Martin Gregorie <martin@address-in-sig.invalid> - 2013-10-02 19:49 +0000
            Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-04 10:48 -0700
              Re: Local database library Martin Gregorie <martin@address-in-sig.invalid> - 2013-10-05 15:43 +0000
                Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-05 11:19 -0700
          Re: Local database library Arne Vajhøj <arne@vajhoej.dk> - 2013-10-02 22:05 -0400
            Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-04 10:57 -0700
              Re: Local database library Arne Vajhøj <arne@vajhoej.dk> - 2013-10-04 22:00 -0400
                Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-05 11:28 -0700
                Re: Local database library Arne Vajhøj <arne@vajhoej.dk> - 2013-10-05 15:15 -0400
                Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-05 12:49 -0700
  Re: Local database library "John B. Matthews" <nospam@nospam.invalid> - 2013-10-02 15:37 -0400
    Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-04 11:02 -0700
      Re: Local database library Lew <lewbloch@gmail.com> - 2013-10-04 15:56 -0700
        Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-05 12:06 -0700
          Re: Local database library Lew <lewbloch@gmail.com> - 2013-10-15 16:41 -0700
            Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-26 12:08 -0700
              Re: Local database library Martin Gregorie <martin@address-in-sig.invalid> - 2013-10-26 21:04 +0000
                Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-26 18:58 -0700
              Re: Local database library Arne Vajhøj <arne@vajhoej.dk> - 2013-10-26 18:39 -0400
                Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-26 19:04 -0700
            Re: Local database library Arne Vajhøj <arne@vajhoej.dk> - 2013-10-26 18:33 -0400

csiph-web