Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help with school project

 
Dudu Yohanshvilli
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I got homework to make a worker list, I have to make it with 3 files:
1-MYSQL connection
2-WorkerLoad - loads from the database
3-WorkersInfo - prints the database info
I succeded to the first 2 but having troubles with the third, help please??
the first file is:


the second:


the third:


I don't know why, but in the third, the FOR don't work


(sorry for the bad english)
 
Campbell Ritchie
Sheriff
Pie
Posts: 49729
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

What do you mean by not working? We need to know more details.
I suggest you precede that for loop by a line like this
 
Dudu Yohanshvilli
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Welcome to the Ranch

What do you mean by not working? We need to know more details.
I suggest you precede that for loop by a line like this


First- Thank You!!!,
I used your suggestion, and I don't know why but it says that I have 0 elements, when I need to have 2, but there is what I need:
I have in MySql a table called "workers"
it contains ID and Name
lets say I have 2 workers,
id: 1, name: Dudu
id: 2, name: James

I want it to connect to the database, collect the information of the workers (id+name)
and then print it, all this need to be done with 3 different pages
1 for the connection to the MYSQL
1 for loading
and the last 1 for printing

something is wrong, I think with the loading, but can't figure out what is wrong!!

P.S:
I found the problem, when I do getInstance().getWork(); I don't know why but it returns 0 instead of 2 when I print the work.size();
I think it don't save the work list, any suggestions??

I can't find how to fix it=[
 
Praveen Kumar M K
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In WorkerLoad, I dont see a call being made to the method loadFromDb.
 
Dudu Yohanshvilli
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Praveen Kumar M K wrote:In WorkerLoad, I dont see a call being made to the method loadFromDb.

 
Praveen Kumar M K
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh so your running class is WorkerLoad!(When you said that the second class succeeded, it put me off track)

instance is a static variable, but the very first line of main creates a new WorkerLoad object. So where are you connecting that to instance
 
Dudu Yohanshvilli
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Praveen Kumar M K wrote:Oh so your running class is WorkerLoad!(When you said that the second class succeeded, it put me off track)

instance is a static variable, but the very first line of main creates a new WorkerLoad object. So where are you connecting that to instance

in WorkersInfo.java:

when I put the line:

under

it returns 0, when actully it need to return 2,

but when I put the same line in WorkerLoad.java inside the loadFromDB under

first it return 1, then 2 (thats ok because I call the function twice, and it has to be 2)


so the problem is somewhere in WorkerInfo with the get instnace,

p.s:
there is "WorkersInfo" and "WorkerInfos" don't get confused =]
 
Praveen Kumar M K
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, this is you main function



And this is the call in check method


Here you are fetching the static instance variable and calling the getWork method on it. Has this static instance variable been assigned to anything?

abc.getWork() is not equal to WorkerLoad.getInstance().getWork();
 
Dudu Yohanshvilli
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow!! thank you very much!!! I am sitting on this error for more then 3 hours!! I think even more then 5 hours, thank you very much!! it works now=]
and again, thank you!!
 
Praveen Kumar M K
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome! Do share here the change that you did, so that other ranchers can benefit.
 
Dudu Yohanshvilli
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Praveen Kumar M K wrote:Welcome! Do share here the change that you did, so that other ranchers can benefit.

The changes something little:
in WorkerLoad change the main to:


and in WorkerInfo
in the check() class
delete the work variable and add to the begginging:


and everything else is the same!
 
Praveen Kumar M K
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, but wouldnt it be easier to make just this change in your main function



The idea here with the static instance is to work with only ONE instance of WorkerLoad object, else it would be of no use.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic