tom davies

Ranch Hand
+ Follow
since Apr 27, 2012
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
8
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by tom davies

I have a query which i am using to find the log in duration of users which i have added below.
I now want to modify it so instead of finding the difference between times it finds the web requests between those times from the same user.
I will do this by searching the WebProxy table with the columns
aDate | aTime | UserIP | WebAddress
The time slots are find using the username and finding entries where the message is LIKE '%logged in%' and the associated username where the IP matches and the message is LIKE '%logged out%'
The webProxy results will have to match the IP and be between the time slots found in T1 and T2.
I have had this working with Separate queries and using ArrayLists to store time slots but from my previous topic i have been trying to change these to single queries and ResultSets

Stevens Miller wrote:Well... we need to see how your ResultSet is defined. Might as well go ahead and post your whole program.



I think i may be getting the NullPointerException due to my SQL queries. Using my other searches i can enter details which will yield no results and i get the blank table which is what i want, but other searches i get the error. I will make some changes to the queries and see if that works.
Line 75 is line 03 below. I pass the ResultSet as a parameter into TableResultsGUI and store the ResultSet as one of my instance variables through the constructor.
Then when i create the JTable i call the set model method below. This all works fine with correct ResultSets just not ones yielding no results.

Paul Clapham wrote:

tom davies wrote:The problem i have with producing the table model is it gives me null pointer exceptions so i would rather i dealt with the issue before it got that far.



Then you're doing it wrong. It should be extremely simple to create a table model and then put all of the records from the ResultSet into it. If there are no records, that shouldn't be a problem.



Hi Paul, below i have added the code which creates my table model and also the error that i get.



Example error, Line 260 in TableResultsGUI being line 12 in the above code.


Fred i am not sure what you mean by my results variable going out of scope, but there is indeed more than that code snippet, that is just the only addition to my working code so that i could call the method i mentioned above.
The fact there is rs and rsArray will not make a difference now. There are two result sets that could be passed to TableResultsGUI so i am doing a check on the first ResultSet rs.

Is there not a way of perhaps creating a new array from the one i want to test, then doing a check on that to determine if its empty or not? Seems to much extra work to do though. The problem i have with producing the table model is it gives me null pointer exceptions so i would rather i dealt with the issue before it got that far.
I KNow how to check if a ResultSet is empty but for some reason it keeps telling me my ResultSet is empty even though i know it isn't.
As part of a program i am developing, a query is executed, i then get that ResultSet. So far i have just been sending it to another JFrame that displays it in a JTable. I cant guarantee if the ResultSet actually has results or not so i have set up method which checks this and returns a boolean if its true or not. The problem is it always returns false even though i know its not.
I dont understand how checking the result set returns a false indicating its empty, but if i send it directing to TableResultsGUI it will display fine . .

The bit of code calling my method


My method to check the ResultSet
I have made some changes below to put the updating of the labels into separate methods.
The code i have showed is part of an actionListener on my two buttons "Roll" and "Hold"
When Roll is pressed i check whether it equals 1 if so its then the servers turn to roll.
The Thread.sleep() is in the serverRoll() method of pigGameProxy() which is my web service.
I didn't think that would effect my GUI as the updating of the Label is done before and after the serverRoll method is called.
I have added println()'s to my new methods serverStartView() and serverEndView() and they print out correctly. I could try a new thread and see if that solves the issue though.

Also Campbell the Thread.sleep() call is just to add a small pause to the game so the user can see that the server is taking their turn.

5 years ago
I have a simple game to practice using web services. Basically a user playing against the computer in a dice roll game.
The game works fine but i want to add a message to say whos turn it is so "your turn" or "computer turn".
For some reason the JLabel wont update when i want it to. As you can see in the code below, if the users rolls a 1 then i want to set my JLabel, get the user total, let the computer play the game, update the computers score and then set my JLabel back again.
On the server end the computer will roll between 1 and 3 times with a sleep after each roll of 1/2 a second. This gives enough time for the server turn message to display and not to long that it slows the game down.
If i just keep the server message in the code below then the JLabel will update but only after the server has rolled. How can i get it to execute in the order i want it to, and display my messages when i want them?

5 years ago

Paul Mrozik wrote:Okay, wait, I think I missed something here. You need actual x values, y values, and z values. In that case, I'd recommend creating a totally separate object, something like:



You can then extract x and y to plot your plane.




I have created an ArrayList of co ordinates and then i loop through and plot them. It seems to be working in all 3 planes this way.
5 years ago

Paul Mrozik wrote:That looks about right, though I'd probably do the reverse in terms of variable names:




So now you need to take it one step further, for a 3d array, which means you need to go a little deeper for the z and you'll need x and y to be constant.



So for the 3D array, if i am still looking at the x-y plane i could have the same two for loops as above but i keep z the same throughout. Then increase z to get the next slice etc?
I think understand it better now, Thank you!
5 years ago

Paul Mrozik wrote:

tom davies wrote:Yes im aware that they will be stored [x][y][z] but i am asking how do i access them and pull them from this array.

Say i want to do the x-y plane first, could someone explain how i would get the values i want from the 3d array? is it a case of keeping the y and z values the same an getting each x value, then increment y and z by one and get the next x values? I know the dimensions of the dataset if that helps as well.



I'm assuming you mean you want to iterate the array, as in go through each item. First, perhaps it would be easier for you to start off with a 2D array and then go from there. You're right about keeping one value constant, so you'd want

x y
arr[0][0]
arr[0][1]
arr[0][2]

So you're incrementing y, while keeping x constant. Hint: Use two for loops.



Thanks. For a 2d array if im looking to extract all the x values would i be looking at something like this.



A mix of pseudo in there but i think you get the idea.
5 years ago
Yes im aware that they will be stored [x][y][z] but i am asking how do i access them and pull them from this array.

Say i want to do the x-y plane first, could someone explain how i would get the values i want from the 3d array? is it a case of keeping the y and z values the same an getting each x value, then increment y and z by one and get the next x values? I know the dimensions of the dataset if that helps as well.
5 years ago
I have a 3 dimensional array if ints but i am drawing a blank on how to access individual values.
I plan to plot them in 2d planes so i want to be able to extract all the x values, all the y values and all the z values to achieve this.
I know in a normal array you can access elements by the index so array[1] but the fact its 3 dimensional is confusing me slightly.
So if anyone could help me to extract all of the x y and z co ordinates that would be great.
5 years ago
It appears the problem is solved now. I just created another thread and put everything you see there into that thread as it was the actual reading of the files causing it to lock.
Also the variation in performance was mainly down to the fact the files on the other computers i tested were being accessed through a network and not local to those machines. It now processes to quick on my machine to test it properly but being very quick i can access other parts of the GUI which i couldnt before. I will do some more testing on other machines but i think it is resolved now.

Manuel Petermann wrote:For starters yes.
Anyway, You wouldn't solve your initial problem that way.
If your databaseLog would simply extend SwingWorker you would end up creating exactly as many new workers as there are files.
That is a bad idea for your problem because as far as i know most filesystems cannot read more than one file at a single point in time anyways.
The fact that a SwingWorker is limited to 10 distinct threads is just a sidenote to that.
Ps:
Think about what you also might want to do in a separate thread.
Pps:
Oh You just need 1 thread/SwingWorker for that.



Would i just have one SwingWorker which handles what ive already got displayed above, so the SwingWorker would select the files and then call the databaseLog etc.