• Post Reply Bookmark Topic Watch Topic
  • New Topic

Intermediate question by a newbie java programmer  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create a layer (or a class) that will look in the database and take the min, max, and mean.

Then another class that would test that class and return the results (min, max, mean)

I have a class that access a database to allow insertions, deletions, updates, on, where, groupby, order by (using sql queries). And another class that tests that class and returns the results.

So now I want (like I said in the 1st paragraph) a class that access a database and looks for stats (mentioned above), a second class that tests that class and returs those (stats) results.

Where do I begin. Those two classes that I already have kinda helps me create the other two classes that I want to make, but I don't know where to begin.
 
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"IronMaiden83,"

Welcome to JavaRanch!

Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names, with a first and a last name.

You can edit your name here.

Thank you for your prompt attention, and enjoy the ranch!

-Marc
 
Nelly Vercetti
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed it to Nelly. I hope that suits better.
[ February 11, 2006: Message edited by: Nelly ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nelly:
I changed it to Nelly. I hope that suits better.

It's closer, but we need a first and a last name. Thanks!

Now, I'm a little unclear on what you're doing, but it sounds to me like you will want instances of the classes you already have as members of your new classes.

For example, if you're "trying to create a layer (or a class) that will look in the database and take the min, max, and mean" and you already "have a class that access a database," then this suggests something like...

I don't want to go too far with this without knowing if that's what you're really after. Maybe I'm way off...
 
Nelly Vercetti
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, so I have database (MYSQL+Tomcat) with a table called payment (among other tables) that has values (in numbers) and I want to take those values and return the max value, the min value, and the mean (I have 3 rows).

The other class would test that class and return the values. The first one would just access the database and do the calculations, but not return them.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nelly Vercetti:
... The other class would test that class and return the values. The first one would just access the database and do the calculations, but not return them.

I'm still not clear on this...
  • Why are these separate classes? Do you mean methods instead of classes?
  • What exactly do you mean by "test that class"?
  • Where exactly are you stuck? Do you have code to read the values from the database?
     
    Nelly Vercetti
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I think is better if I just point out the errors (I have started to typed out some things that may work for what I want).

    Right now I am getting a ClassCastException on this line:

    String payment_received = (String) row.get(1); // This is suppose to get the //values from row1 of the payment window but it won't even read it

    The line before that I have:
    Long id = (Long) row.get(0); //This line is suppose to get the ID of the //customer, which it does as I tested it using system.out.println

    Now the line that doesn't work it has a timestamp (date type) for payment_received using MySQL Administrator (Thats how I created the database).
    [ February 11, 2006: Message edited by: Nelly Vercetti ]
     
    marc weber
    Sheriff
    Posts: 11343
    Java Mac Safari
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Nelly Vercetti:
    ...Right now I am getting a ClassCastException on this line:

    String payment_received = (String) row.get(1); ...

    ...it has a timestamp (date type) for payment_received using MySQL Administrator...

    The return type of the get method is not compatible with String. I don't know SQL, but it sounds like you want to cast this as a java.sql.Timestamp or maybe java.util.Date (a superclass of Timestamp). You can then call toString on this if needed.
    [ February 11, 2006: Message edited by: marc weber ]
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!