Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.databases > #616 > unrolled thread
| Started by | Kevin Nathan <knathan@project54.com> |
|---|---|
| First post | 2013-10-01 13:52 -0700 |
| Last post | 2013-10-26 18:33 -0400 |
| Articles | 20 on this page of 26 — 5 participants |
Back to article view | Back to comp.lang.java.databases
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
Page 1 of 2 [1] 2 Next page →
| From | Kevin Nathan <knathan@project54.com> |
|---|---|
| Date | 2013-10-01 13:52 -0700 |
| Subject | Local database library |
| Message-ID | <20131001135230.66af12f9@efreet.linux> |
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. However, being new to Java, I am not sure how that should be structured in source files. So, my question is: Does anyone know of a good tutorial on how to build a library of routines in Java? I'm coming up short in my web searching, probably because I haven't found the right incantations to use (and not yet knowledgeable enough in Java to know what I need). I am a little bit rushed and "learning on the fly" so there is not much time to dig through many tutorials, although I sure wish I could. I don't like this "brute-force" method everyone has used so far, but it's the easiest way to make progess. I just don't want to have to redo everything once we are up and running. Thanks for any help you can provide! :-) -- Kevin Nathan (Arizona, USA) Linux is not a destination, it's a journey -- enjoy the trip! Linux 3.7.10-1.16-desktop 13:41pm up 12 days 23:53, 14 users, load average: 0.33, 0.37, 0.42
[toc] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2013-10-01 17:38 -0400 |
| Message-ID | <524b40ba$0$304$14726298@news.sunsite.dk> |
| In reply to | #616 |
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. However, being new to > Java, I am not sure how that should be structured in source files. So, > my question is: Does anyone know of a good tutorial on how to build a > library of routines in Java? I'm coming up short in my web searching, > probably because I haven't found the right incantations to use (and > not yet knowledgeable enough in Java to know what I need). > > I am a little bit rushed and "learning on the fly" so there is not much > time to dig through many tutorials, although I sure wish I could. I > don't like this "brute-force" method everyone has used so far, but it's > the easiest way to make progess. I just don't want to have to redo > everything once we are up and running. Thanks for any help you can > provide! :-) 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++. 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). Arne
[toc] | [prev] | [next] | [standalone]
| From | Kevin Nathan <knathan@project54.com> |
|---|---|
| Date | 2013-10-01 15:41 -0700 |
| Message-ID | <20131001154157.7f37e588@efreet.linux> |
| In reply to | #617 |
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
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2013-10-01 20:53 -0400 |
| Message-ID | <524b6e8d$0$304$14726298@news.sunsite.dk> |
| In reply to | #618 |
On 10/1/2013 6:41 PM, Kevin Nathan wrote:
> 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.
The Java standard and somewhat enforced by the tools is a source
file per top level type.
So the object model more or less determines the source files.
>> 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.
Java is OO like C++.
So:
getTransData()
getBuyerData()...
assumes that the methods are in the same class as the calling method.
If you want to move it out you will need to call a method on an
object.
Maybe something like:
TransactionManager txm = new TransactionManager();
List<Transaction> txl = txm.getTransactions();
Arne
[toc] | [prev] | [next] | [standalone]
| From | Kevin Nathan <knathan@project54.com> |
|---|---|
| Date | 2013-10-02 10:09 -0700 |
| Message-ID | <20131002100935.0eacf609@efreet.linux> |
| In reply to | #619 |
On Tue, 01 Oct 2013 20:53:32 -0400 Arne Vajhøj <arne@vajhoej.dk> wrote: >So: > >getTransData() >getBuyerData()... > >assumes that the methods are in the same class as the calling method. > >If you want to move it out you will need to call a method on an >object. > >Maybe something like: > >TransactionManager txm = new TransactionManager(); >List<Transaction> txl = txm.getTransactions(); > I have, so far, determined to use one source file per table and I *think* I've figured out the library structure. I now have two files in it and they seem to work although some of the Swing stuff in the main program has stopped working (I probably deleted something I should not have when cleaning up the DB code). Your two code lines above have gotten me thinking of some other options and questions, so I will be digging into that. That's pretty much the format used in the C++ code, but that code is very poorly written so it's hard to understand a lot of what the previous coders were doing. As I said, I'm very new to Java and really need a month to learn things before jumping in, but I have to sneak that in, in between coding sessions. :-) Thanks for all your help, Arne! I have a lot of other questions, but I will be researching them on the internet. I will be back if I have problems finding the answers. I much prefer to figure things out for myself, but am not afraid to ask the occasional stupid question! :-) -- Kevin Nathan (Arizona, USA) Linux is not a destination, it's a journey -- enjoy the trip! Linux 3.7.10-1.16-desktop 09:56am up 13 days 20:09, 14 users, load average: 0.63, 0.61, 0.56
[toc] | [prev] | [next] | [standalone]
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Date | 2013-10-02 19:49 +0000 |
| Message-ID | <l2htcj$j8p$1@dont-email.me> |
| In reply to | #620 |
On Wed, 02 Oct 2013 10:09:35 -0700, Kevin Nathan wrote: > Your two code lines above have gotten me thinking of some other options > and questions, so I will be digging into that. That's pretty much the > format used in the C++ code, but that code is very poorly written so > it's hard to understand a lot of what the previous coders were doing. > One JDBC wrapper class per table may work. Then again its likely to lead you into tangles with SQL that accesses more than one table, i.e. doing joins. In that case a bit of data analysis[*] may pay off because things may be easier if you can use a single class to encapsulate all access to a tightly linked group of tables [*] This means looking at the database schema if there is a current version or draw one up if there isn't. There are some good tools for extracting entity-relationship diagrams from the schema if your shop has a budget for this sort of tool. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |
[toc] | [prev] | [next] | [standalone]
| From | Kevin Nathan <knathan@project54.com> |
|---|---|
| Date | 2013-10-04 10:48 -0700 |
| Message-ID | <20131004104829.4bd78e5b@efreet.linux> |
| In reply to | #622 |
On Wed, 2 Oct 2013 19:49:39 +0000 (UTC) Martin Gregorie <martin@address-in-sig.invalid> wrote: >One JDBC wrapper class per table may work. Then again its likely to >lead you into tangles with SQL that accesses more than one table, i.e. >doing joins. In that case a bit of data analysis[*] may pay off >because things may be easier if you can use a single class to >encapsulate all access to a tightly linked group of tables > I hadn't thought of that. What I have started to do (and it's not yet working) is to create a "DBaccess" library under "net.companyname.connect" and right now I have a "connect.java" file in that makes the connection to the database and a "transaction.java" that works with the transaction table. My source file in a different project is not seeing these, but I think it might be improper setup in NetBeans since I'm learning *that* too! :-) >[*] This means looking at the database schema if there is a current >version or draw one up if there isn't. There are some good tools for >extracting entity-relationship diagrams from the schema if your shop >has a budget for this sort of tool. > I have some free tools for this under Linux and plan to do this. However, I am quite familiar with the data structure since I worked with it (under C, and later C++) for six years (some time ago) and not too much has changed. But I believe there are probably some poor design choices being used since it was originally designed by someone with minimal programming experience and almost no data experience. I cleaned up a few things when I worked for them previously and want to do more once we get the new version up and running. I know that's the backward way to do it, but we're quickly reaching the point where we cannot make changes to the code (under Qt3) while trying to upgrade the clients' computers. You will probably see me posting in here again! :-) Thanks for the tips! -- Kevin Nathan (Arizona, USA) Linux is not a destination, it's a journey -- enjoy the trip! Linux 3.7.10-1.16-desktop 10:38am up 15 days 20:51, 14 users, load average: 0.87, 0.75, 0.64
[toc] | [prev] | [next] | [standalone]
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Date | 2013-10-05 15:43 +0000 |
| Message-ID | <l2pc3f$442$1@dont-email.me> |
| In reply to | #624 |
On Fri, 04 Oct 2013 10:48:29 -0700, Kevin Nathan wrote: > I hadn't thought of that. What I have started to do (and it's not yet > working) is to create a "DBaccess" library under > "net.companyname.connect" and right now I have a "connect.java" file in > that makes the connection to the database and a "transaction.java" that > works with the transaction table. My source file in a different project > is not seeing these, but I think it might be improper setup in NetBeans > since I'm learning *that* too! :-) > The following summarises what I did for a small system that has non- interactive CLI programs as well as a few GUI utilities that do updates and run enquiries on the DB. I ended with a superclass containing the methods connect() and close() to start and stop the database connection plus other methods to handle common requirements such as reporting DB access failures. There's a subclass for each program. The methods in these each encapsulate an SQL transaction. Data is passed as arguments and the return value indicates success or failure. Where a transaction fills a JTable a reference to its Model is passed into the method, which can put all the rows returned by the SQL query into the Model. This is not a particularly OO design choice, but it does a good job of encapsulating the JDBC elements of a program and gives reasonable separation between the logic implementing each transaction type. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |
[toc] | [prev] | [next] | [standalone]
| From | Kevin Nathan <knathan@project54.com> |
|---|---|
| Date | 2013-10-05 11:19 -0700 |
| Message-ID | <20131005111901.75595916@efreet.linux> |
| In reply to | #630 |
On Sat, 5 Oct 2013 15:43:43 +0000 (UTC) Martin Gregorie <martin@address-in-sig.invalid> wrote: >On Fri, 04 Oct 2013 10:48:29 -0700, Kevin Nathan wrote: > >> I hadn't thought of that. What I have started to do (and it's not yet >> working) is to create a "DBaccess" library under >> "net.companyname.connect" >> >The following summarises what I did for a small system that has non- >interactive CLI programs as well as a few GUI utilities that do >updates and run enquiries on the DB. > >I ended with a superclass containing the methods connect() and close() >to start and stop the database connection plus other methods to handle >common requirements such as reporting DB access failures. There's a >subclass for each program. The methods in these each encapsulate an >SQL transaction. Data is passed as arguments and the return value >indicates success or failure. Where a transaction fills a JTable a >reference to its Model is passed into the method, which can put all >the rows returned by the SQL query into the Model. > Sounds like just about what I need! I will look into doing it that way... -- Kevin Nathan (Arizona, USA) Linux is not a destination, it's a journey -- enjoy the trip! Linux 3.7.10-1.16-desktop 11:17am up 16 days 21:30, 14 users, load average: 0.80, 0.62, 0.61
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2013-10-02 22:05 -0400 |
| Message-ID | <524cd0e4$0$298$14726298@news.sunsite.dk> |
| In reply to | #620 |
On 10/2/2013 1:09 PM, Kevin Nathan wrote: > On Tue, 01 Oct 2013 20:53:32 -0400 > Arne Vajhøj <arne@vajhoej.dk> wrote: >> So: >> >> getTransData() >> getBuyerData()... >> >> assumes that the methods are in the same class as the calling method. >> >> If you want to move it out you will need to call a method on an >> object. >> >> Maybe something like: >> >> TransactionManager txm = new TransactionManager(); >> List<Transaction> txl = txm.getTransactions(); > > I have, so far, determined to use one source file per table and I > *think* I've figured out the library structure. I now have two files in > it and they seem to work Remember to separate the data class and the class that manage the data class. > Your two code lines above have gotten me thinking of some other options > and questions, so I will be digging into that. That's pretty much the > format used in the C++ code, It is rather general OO style. > I much prefer to figure things out for > myself, but am not afraid to ask the occasional stupid question! That is the way to learn. Arne
[toc] | [prev] | [next] | [standalone]
| From | Kevin Nathan <knathan@project54.com> |
|---|---|
| Date | 2013-10-04 10:57 -0700 |
| Message-ID | <20131004105704.7e132036@efreet.linux> |
| In reply to | #623 |
On Wed, 02 Oct 2013 22:05:22 -0400
Arne Vajhøj <arne@vajhoej.dk> wrote:
>On 10/2/2013 1:09 PM, Kevin Nathan wrote:
>>
>> I have, so far, determined to use one source file per table and I
>> *think* I've figured out the library structure. I now have two files
>> in it and they seem to work
>
>Remember to separate the data class and the class that manage the data
>class.
>
This is what I am trying to do, let me know if I am going far afield
here:
create a "DBaccess" library under "net.companyname.connect"
"connect.java" file to connect to the database
"transaction.java" to access the transaction table.
...
Right now I have that setup as a project under NetBeans and a separate
project "penner" (weighs the animals and assigns them to pens). The
calls to transaction.java aren't being seen in penner, so I think I
have something not setup right in NetBeans (I am learning *this*, as
well!) . I need to go through more tutorials on this, I guess.
--
Kevin Nathan (Arizona, USA)
Linux is not a destination, it's a journey -- enjoy the trip!
Linux 3.7.10-1.16-desktop
10:49am up 15 days 21:02, 14 users, load average: 0.66, 0.46, 0.52
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2013-10-04 22:00 -0400 |
| Message-ID | <524f72c2$0$300$14726298@news.sunsite.dk> |
| In reply to | #625 |
On 10/4/2013 1:57 PM, Kevin Nathan wrote: > On Wed, 02 Oct 2013 22:05:22 -0400 > Arne Vajhøj <arne@vajhoej.dk> wrote: > >> On 10/2/2013 1:09 PM, Kevin Nathan wrote: >>> >>> I have, so far, determined to use one source file per table and I >>> *think* I've figured out the library structure. I now have two files >>> in it and they seem to work >> >> Remember to separate the data class and the class that manage the data >> class. >> > > This is what I am trying to do, let me know if I am going far afield > here: > > create a "DBaccess" library under "net.companyname.connect" > > "connect.java" file to connect to the database > "transaction.java" to access the transaction table. > ... I am somewhat skeptical about a class to encapsulate Connection - they are often unnecesarry complexity. My point was that you should have two classes: - Transaction, to have data for a single transaction - TransactionManager, to retrieve one or retrieve all or save one Transaction Note that by convention Java classes names start with an uppercase letter. Arne
[toc] | [prev] | [next] | [standalone]
| From | Kevin Nathan <knathan@project54.com> |
|---|---|
| Date | 2013-10-05 11:28 -0700 |
| Message-ID | <20131005112826.2b95626d@efreet.linux> |
| In reply to | #629 |
On Fri, 04 Oct 2013 22:00:31 -0400 Arne Vajhøj <arne@vajhoej.dk> wrote: >I am somewhat skeptical about a class to encapsulate Connection - they >are often unnecesarry complexity. > Ok, I will do more research on the Connection item. >My point was that you should have two classes: >- Transaction, to have data for a single transaction >- TransactionManager, to retrieve one or retrieve all or save one >Transaction > That makes sense. I should move to a higher level, but I have all the raw SQL from the C++ program for all the complex statements with the appropriate JOINs, sub SELECTs, etc., that have been working for years and I'm not sure I'm up to the task of modelling that, yet. >Note that by convention Java classes names start with an uppercase >letter. > Yes, I name my classes with initial uppercaes -- I'm just so used to naming files with lowercase and dashes. I'm going to have to work on that -- it's hard to break a decades-long habit! :-) -- Kevin Nathan (Arizona, USA) Linux is not a destination, it's a journey -- enjoy the trip! Linux 3.7.10-1.16-desktop 11:20am up 16 days 21:33, 14 users, load average: 0.44, 0.54, 0.58
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2013-10-05 15:15 -0400 |
| Message-ID | <5250656d$0$300$14726298@news.sunsite.dk> |
| In reply to | #632 |
On 10/5/2013 2:28 PM, Kevin Nathan wrote: > On Fri, 04 Oct 2013 22:00:31 -0400 > Arne Vajhøj <arne@vajhoej.dk> wrote: >> Note that by convention Java classes names start with an uppercase >> letter. >> > > Yes, I name my classes with initial uppercaes -- I'm just so used to > naming files with lowercase and dashes. I'm going to have to work > on that -- it's hard to break a decades-long habit! :-) In case you have not found it yet: http://www.oracle.com/technetwork/java/javase/documentation/codeconvtoc-136057.html Arne
[toc] | [prev] | [next] | [standalone]
| From | Kevin Nathan <knathan@project54.com> |
|---|---|
| Date | 2013-10-05 12:49 -0700 |
| Message-ID | <20131005124910.2d1bff21@efreet.linux> |
| In reply to | #634 |
On Sat, 05 Oct 2013 15:15:55 -0400 Arne Vajhøj <arne@vajhoej.dk> wrote: >In case you have not found it yet: > >http://www.oracle.com/technetwork/java/javase/documentation/codeconvtoc-136057.html > Thanks! Yes, I already have it in my bookmarks... :-) -- Kevin Nathan (Arizona, USA) Linux is not a destination, it's a journey -- enjoy the trip! Linux 3.7.10-1.16-desktop 12:48pm up 16 days 23:01, 14 users, load average: 0.50, 0.58, 0.77
[toc] | [prev] | [next] | [standalone]
| From | "John B. Matthews" <nospam@nospam.invalid> |
|---|---|
| Date | 2013-10-02 15:37 -0400 |
| Message-ID | <nospam-29AECA.15371802102013@news.aioe.org> |
| In reply to | #616 |
In article <20131001135230.66af12f9@efreet.linux>, Kevin Nathan <knathan@project54.com> 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. However, being new to > Java, I am not sure how that should be structured in source files. > So, my question is: Does anyone know of a good tutorial on how to > build a library of routines in Java? I'm coming up short in my web > searching, probably because I haven't found the right incantations to > use (and not yet knowledgeable enough in Java to know what I need). > > I am a little bit rushed and "learning on the fly" so there is not > much time to dig through many tutorials, although I sure wish I > could. I don't like this "brute-force" method everyone has used so > far, but it's the easiest way to make progess. I just don't want to > have to redo everything once we are up and running. Thanks for any > help you can provide! :-) If you go with NetBeans, here's more details on adding and using libraries: <http://stackoverflow.com/q/1975973/230513> NetBeans makes it easy to explore JPA, as suggested here: <http://stackoverflow.com/q/3422516/230513> In this example, a Customer entity and controller generated from the database are used to display names in a JComboBox. <http://stackoverflow.com/q/3422516/230513> -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews>
[toc] | [prev] | [next] | [standalone]
| From | Kevin Nathan <knathan@project54.com> |
|---|---|
| Date | 2013-10-04 11:02 -0700 |
| Message-ID | <20131004110242.1be4f5ea@efreet.linux> |
| In reply to | #621 |
On Wed, 02 Oct 2013 15:37:18 -0400 "John B. Matthews" <nospam@nospam.invalid> wrote: >In article <20131001135230.66af12f9@efreet.linux>, > Kevin Nathan <knathan@project54.com> wrote: > >> So, my question is: Does anyone know of a good tutorial on how to >> build a library of routines in Java? > >If you go with NetBeans, here's more details on adding and using >libraries: > ><http://stackoverflow.com/q/1975973/230513> > >NetBeans makes it easy to explore JPA, as suggested here: > ><http://stackoverflow.com/q/3422516/230513> > >In this example, a Customer entity and controller generated from the >database are used to display names in a JComboBox. > ><http://stackoverflow.com/q/3422516/230513> > Thanks for the links! That's my work for today, I guess! I don't like stumbling around in the dark, so I just have to take the time necessary to get a handle on all of this... -- Kevin Nathan (Arizona, USA) Linux is not a destination, it's a journey -- enjoy the trip! Linux 3.7.10-1.16-desktop 10:58am up 15 days 21:11, 14 users, load average: 0.42, 0.52, 0.58
[toc] | [prev] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2013-10-04 15:56 -0700 |
| Message-ID | <d50f8d5a-bf95-4d95-bc93-6a53b0a16522@googlegroups.com> |
| In reply to | #626 |
Kevin Nathan wrote: >>> So, my question is: Does anyone know of a good tutorial on how to >>> build a library of routines in Java? The Java Tutorial. http://docs.oracle.com/javase/tutorial/ Read about JAR files. All a "library of routines" is is a JAR file of classes. > Thanks for the links! That's my work for today, I guess! I don't like > stumbling around in the dark, so I just have to take the time > necessary to get a handle on all of this... Since database access in Java is a rich and extremely large area, and you apparently still lack information on how to build any kind of project in Java, that is advisable. There are pitfalls galore in writing just "a local library of database access routines". Most likely you'll wind up with an overblown and unmaintainable mess that people have to shoehorn into their logic with more effort than just using JPA or JDBC themselves. I've done a lot of experimentation with different ways of coding database access in Java, and the flat-out worst was a comprehensive "local library of database access routines". By far the easiest to code and maintain was a non-monolithic JPA approach. But you really should know at least *something* about writing database access before engaging in the overweening presumption of building a "library" for others to use. -- Lew
[toc] | [prev] | [next] | [standalone]
| From | Kevin Nathan <knathan@project54.com> |
|---|---|
| Date | 2013-10-05 12:06 -0700 |
| Message-ID | <20131005120659.39a89f3b@efreet.linux> |
| In reply to | #627 |
On Fri, 4 Oct 2013 15:56:18 -0700 (PDT)
Lew <lewbloch@gmail.com> wrote:
>Kevin Nathan wrote:
>>>> So, my question is: Does anyone know of a good tutorial on how to
>>>> build a library of routines in Java?
>
>The Java Tutorial.
>http://docs.oracle.com/javase/tutorial/
>
>Read about JAR files.
>
>All a "library of routines" is is a JAR file of classes.
>
Yes, I understand that, but as you mention below, I'm very new at Java.
I've been going through tutorials and have a lot more to go through. I
just really need a better handle on Java, overall.
>Since database access in Java is a rich and extremely large area, and
>you apparently still lack information on how to build any kind of
>project in Java, that is advisable.
>
And reading tutorials is what I am doing, now. I was hoping it would be
mostly modifying the structure of the C++ program into Java, but that
doesn't seem to be the case.
>There are pitfalls galore in writing just "a local library of database
>access routines". Most likely you'll wind up with an overblown and
>unmaintainable mess that people have to shoehorn into their logic with
>more effort than just using JPA or JDBC themselves.
>
The current C++ code has a DAO library, written about thirteen years
ago and based on C code for twenty-some years before that, that I
thought I could mimic. Apparently, I can't.
>I've done a lot of experimentation with different ways of coding
>database access in Java, and the flat-out worst was a comprehensive
>"local library of database access routines".
>
I get your point.
>By far the easiest to code and maintain was a non-monolithic JPA
>approach.
>
>But you really should know at least *something* about writing database
>access before engaging in the overweening presumption of building a
>"library" for others to use.
>
I started reading through some info on JPA, and I would like to get
there, eventually. But we have a data structure that's been tested and
working since the mid-1970's. It started in BASIC, of all things, but
quickly migrated to C and stayed there (mostly under Real/32 DOS) for
about 25 years, which was the form I maintained for its last 6 years.
I was in on the beginning of the transition to Linux and C++ but ended
up moving before it was finished. That was nine years ago and the
decision to use Qt3 is now biting them in the butt. Conversion to Qt4
is a nightmare. So, they decided to move to Java which should help
insulate them from OS changes, a bit. They called me to see if I could
help so they didn't have to train someone in the livestock auction
system, since I already was quite familiar with it. A professional
company gave them an estimate of 5,000 man-hours to convert it from Qt3
to Qt4 -- the original program only took one man 60 days to write,
initially. So the decision was made to just rewrite it in a new
language and UI library.
I have a fully-functioning and tested DAO library written in-house
(originally in C, then moved to C++) and wanted to mimic that in Java
using the SQL currently existing. I thought that would be easy. I was
wrong. I also thought that all I'd really need to do was generate new
screens and use much of the C++ logic, just modifying it for use under
Java. I was wrong, again.
This is *not* something for general use by others. We have about 60
clients and add maybe one or two a year, some years. It's only for our
use in-house and will never see the light of day. If they keep me on
long enough, I will redo the program for JPA, but a quick solution is
necessary. Once I learn how to convert SQL like this:
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)";
and even more complex queries into JPA, I will start that process.
Until that happens, I will have to muddle through with the brute force
methods that a previous programmer used...
--
Kevin Nathan (Arizona, USA)
Linux is not a destination, it's a journey -- enjoy the trip!
Linux 3.7.10-1.16-desktop
11:29am up 16 days 21:42, 14 users, load average: 0.67, 0.66, 0.62
[toc] | [prev] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2013-10-15 16:41 -0700 |
| Message-ID | <ec4d1b88-d33a-4b76-a0e6-709319845718@googlegroups.com> |
| In reply to | #633 |
Kevin Nathan wrote: > This is *not* something for general use by others. We have about 60 > clients and add maybe one or two a year, some years. It's only for our > use in-house and will never see the light of day. If they keep me on > long enough, I will redo the program for JPA, but a quick solution is > necessary. Once I learn how to convert SQL like this: > > 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)"; > > and even more complex queries into JPA, I will start that process. That would be insane and stupid. You don't convert queries into JPA; that's utterly backwards. If you have a data orientation, you use straight-up JDBC, not JPA. JPA is for creating persistent *objects*. It is not for creating queries or data sets. > Until that happens, I will have to muddle through with the brute force > methods that a previous programmer used... It is weird to hear SQL described as "brute force". JPA is for object orientation. JDBC is for set orientation. Your queries, if they are reasonably standard SQL, go directly into JDBC 'Statement' objects. (Use 'PreparedStatement'.) Bob's your uncle. -- Lew
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.java.databases
csiph-web