Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes JDBC and Relational Databases and the fly likes OOP and JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "OOP and JDBC" Watch "OOP and JDBC" New topic


Elton Hughes
Ranch Hand

Joined: Jun 19, 2003
Posts: 72
Hello All,
I am new to Java and JDBC and I have a question.
Below is a program that works extremely well, but has one minor annoyance.

So far, so good. The only problem is that I need wage information for grants 201, 501, 542, 604, and 744. Not only that, but there are 10 other SQL statements that need to be run on each grant.
So, is it possible to make an abstract class of almost all of the code and then have concrete class with a main method fill in the rest?
Or, is there a better way of re-using code and not end up with 50 classes (that do work extremely well)??
Thank you for your time.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 31668

First step is to put that main method in an object (for reuse.) Look into using a prepared statement. Then you can pass the id in using the constructor (or a set method) and reuse the sql.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Have you tried LearnNowOnline?
subject: OOP and JDBC