Path: csiph.com!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Kevin Nathan Newsgroups: comp.lang.java.databases Subject: Re: Local database library Date: Tue, 1 Oct 2013 15:41:57 -0700 Lines: 85 Message-ID: <20131001154157.7f37e588@efreet.linux> References: <20131001135230.66af12f9@efreet.linux> <524b40ba$0$304$14726298@news.sunsite.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: individual.net +Kbv6S7dIV9TM1A7YJ4zLgHm/FE2cxWguCQ7IYlB1aKlgwb4/y Cancel-Lock: sha1:/olBttS+wQEGQYQkhdWnl1o3hUc= X-Newsreader: Claws Mail 3.9.0 (GTK+ 2.24.18; i586-suse-linux-gnu) X-Face: %/gp4MCQT=`#JS##?-]V9ksid6OSR@(wbF"bK6wSLO$u,%(N@X~bVhAD+\A_[gRhx*T6=fq "N_5H8.v[&;q0iw!s_wuL05B0xg#OYUkbn#@&U_]fL%o==~2sphc?*L+bicO!POJLG#p'N.]J0/p_w Z^(.kOB%Ob914-V>?GI; Xref: csiph.com comp.lang.java.databases:618 On Tue, 01 Oct 2013 17:38:01 -0400 Arne Vajh=C3=B8j 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:=20 getTransData() getBuyerData()... instead of having this in the main file: try { Statement st =3D (Statement) con.createStatement(); String command =3D "SELECT " + "SELLERID, HEAD, DESCRIP, " + "ROUND(WEIGHT/HEAD) AS AVG_WGT, " + "WEIGHT, BUYERID, PRICE, BUYERPEN, " + "(SELECT name FROM seller " + "WHERE date=3D(SELECT MAX(start) FROM sales WHERE sel=3D1) " + "AND number=3Dtrans.sellerid) AS NAME, " + "(SELECT GROUP_CONCAT(tag_num) FROM backtags " + "WHERE trans_id=3Dtrans.trans_id and ckin_date=3D" + "(SELECT MAX(start) FROM sales WHERE sel=3D1)=20 + "GROUP BY trans_id) AS ALLTAGS " + "FROM trans " + "WHERE TRANS_ID =3D '" + transNum + "' " + "AND date=3D(SELECT MAX(start) FROM sales WHERE sel=3D1)"; ResultSet rs =3D st.executeQuery(command);=20 } 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. --=20 Kevin Nathan (Arizona, USA) =20 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