Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!

joe weakers

Ranch Hand
+ Follow
since May 31, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by joe weakers

Cheers Ilja. Thanks for your reply. I had a look in the javadocs for information about TreeSets but I struggled to find any examples of its implementation. Is there any chance that you may know of a link to an example of how a TreeSet is implemented. Sorry but I am having difficulty getting my head around the javadocs. Joe
15 years ago
Hi there. I have a Vector v of InterestFeature objects that has a constant size of 27. In my class InterestFeature, I have set and get methods for setting and getting the InterestFeature objects' names and current scores. Therefore all the objects in v have a name and current score associated with them. What I need to do now is to parse thru all the elements in v and insert the objects' names into a new data structure x in the order of their current scores, i.e. for each value in v insert it into x based on its score where the values in x are ordered from highest score to lowest score. I know there are stacks, lists, sorting algorithms, etc. out there but I was hoping that somebody might save me the hassle of spending a lot of effort finding the most suitable solution. Thnaks a lot, Joe
15 years ago
Hi there. My problem is as follows:
The set X is composed of 30 unique elements. I have three vectors, A, B, and C, that hold unique elements from X. In other words A,B, and C are all subsets of set X. The size of A ranges from 1-12 and cannot be 0. The size of b ranges from 0-12 and can be empty. The size of C ranges from 1-12 and cannot be 0. A,B, and C all contain unique elements.
What is the best way (optimal solution) to finding the intersection of A and B and C? Is using vectors not a good option - there are so few elements in each vector does it really make any difference? I was going to rely on the contains(obj) method that is provided by java.util.Vector. Is this too slow to be using?
I should also state that if an element is in A then it is extremely likely to be either B or C or both. I know the query is vague but any help would be appreciated nonetheless. thnaks a lot, Joe.
15 years ago
Hi guys. Thanks for your reply. Jeanne in response to your advice I updated my code incorporating your suggested changes and the code works fine. My code now looks as follows:

....
ServerConnection sc = new ServerConnection();
PreparedStatement ps1 = sc.conn.prepareStatement("Select feature_id, \n"+
"feature_score from joeweaker.session_interest_features \n"+"where user_id = ? and session_id = ? order by feature_score desc, feature_id");
PreparedStatement ps2 = sc.conn.prepareStatement("Select feature_id, area_id from \n"+"joeweaker.interest_area_features where user_id = ? and session_id = ? \n"+"order by area_id, feature_id");
PreparedStatement ps3 = sc.conn.prepareStatement("Select feature_id from \n"+"joeweaker.final_map_frames where user_id = ? and session_id = ? order by \n"+"feature_id");

for(int i = 0; i < session_ids.length; i++)
{
ps1.setInt(1,current_user_id);
ps1.setInt(2,session_ids[i]);
ResultSet rs = ps1.executeQuery();
while(rs.next()){
...}
ps2.setInt(1,current_user_id);
ps2.setInt(2,session_ids[i]);
rs = ps2.executeQuery();
while(rs.next()){
...}
ps3.setInt(1,current_user_id);
ps3.setInt(2,session_ids[i]);
rs = ps3.executeQuery();
while(rs.next()){
...}
rs.close();
}
ps1.close();
ps2.close();
ps3.close();
sc.conn.close();

Shailesh, Avi, as you can see there is no real point in attempting to merge the three queries into one for each iteration of the for loop as the result sets would be longwinded and incoherent. Secondly, I have used functions and procedures before in my code (I am using Oracle database) and question how much better they would be than using PreparedStatements in this particular scenario. The reason I am saying this is that I need to take the results of each sql query and process them in Java based on the value of the session_id as oppose to processing them in the database. Each result set will be processed individually and hence I think it might make more sense to process the result sets in Java. Have you guys any further suggestions. Thnaks a lot for your time, Joe
Hi there. Can anybody offer me some sound advice on the following. I have an array of numbers (size can range from 1....100 depending on certain criteria) and for each number in the array I need to execute three specific SQL queries (hence 300 possible queries). Each query returns quite different result sets and hence joining them is not really an option. Code looks roughly as follows:

.....
String query = null;
ServerConnection sc = new ServerConnection(); //connect to database once
Statement stmt = sc.conn.createStatement(); //create statement once
for(int i = 0; i < session_ids.length; i++) //for each array value
{
query = "select from table1 where session_id = session_ids[i] and ..."
ResultSet rs = stmt.execute(query);
while(rs.next){...}
query = "select from table2 where session_id = session_ids[i] and ..."
ResultSet rs = stmt.execute(query);
while(rs.next){...}
query = "select from table 3 where session_id = session_ids[i] and ..."
ResultSet rs = stmt.execute(query);
while(rs.next){...}
}
rs.close();
stmt.close();
sc.conn.close();
....

My question is as follows. Is this code ok or do I need to create three different Statement and ResultSet objects - one for each query that will be executed for each value in the array? Also is there a need to open and close the connection after each iteration of the for loop? Finally, is there anything seriously wrong with the code or is there a better way of executing up to 300 queries in one method. Thnaks a lot, Joe
I was hoping somebody might be able to help me with this. I keep encountering an error of the form

java.lang.NullPointerException at oracle.jdbc.driver.ScrollableResultSet.close(ScrollableResultSet.java:149)

This error is as a result of changing the format of the JDBC result set.
Initially my code looked lke this:

Statement stmt1 = cont.conn.createStatement(); //no errors
OracleResultSet ors1 = (OracleResultSet)stmt1.executeQuery(query1);

Now the code is as follows:

Statement stmt1 = cont.conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
OracleResultSet ors1 = (OracleResultSet)stmt1.executeQuery(query1);

The error arises when i try to close ors1:
ors1.close(); //error at this line

Can anybody provide a solution to this for me. Thanks a lot, Joe

P.S. the reason I am using Scrollable result sets is explained in my last post in this section.
Hi Samir. Thanks a lot for your reply. I have a little experience with Java beans and from what I hear they are not too difficult to master. However given the choice of employing either a scrollable resultset or using java beans I think I would rather go with the scrollable resultset option. can you give me some advice on how to incorporate the scrollable resultset or where to find some sample code on scrollable resultsets. Thnaks a lot, Joe
can somebody please give me a pointer to a helpful java beans site that goes through the basics of java beans functionality. Thnaks a lot, Joe
Hello there. Is it possible to process a JDBC ResultSet more than once. What I mean is that I want to pass a single result set argument to two different methods that both process the result set in its entirety. Code looks as follows:

OracleResultSet ors1 = (OracleResultSet)stmt1.executeQuery(query1);
checkCFCC(ors1);
gfd.matchFeatureIDs(ors1);

Both the methods parse the entire result set as follows:
while (ors1.next())
{ ...
...
}

Problem is that the result set is empty once the checkCFCC method has finished executing. I tried to intorduce a new OracleResultSet variable as follows:

OracleResultSet ors2 = ors1;

and then pass the two different result sets into the two methods. This did not solve my problem. Can anybody give me a pointer towards a possible solution. Thnaks a lot. Joe
Thanks Mattias. Should have seen that one.
15 years ago
Hi. I am trying to implement the bubble sort algorithm involving an array of PointObjects that I have created. Each PointObject has an integer counter associated with it and I am trying to sort the array in order of increasing counter size. When I run the code below it appears to execute OK and when I debug all seems to be well. However the output of the array is the original array as if the sort has not taken place. Can anybody see anything incorrect here:

PointObject[] sig_points = new PointObject[9]; //sig_points has been filled
PointObject p;
for(int i = (sig_points.length-1); i >= 0; i--){
for(int j = 1; j <= i; j++){
PointObject po1 = (PointObject)sig_points[j-1];
PointObject po2 = (PointObject)sig_points[j];
if(po1.getCounter() > po2.getCounter()){
p = po1;
po1 = po2;
po2 = p;
System.out.println();
}
}
}
for(int k = 0; k < sig_points.length; k++){
PointObject po1 = (PointObject)sig_points[k];
System.out.println(po1.getCounter()); //not printed in increasing order
}

When I run the final for loop the PointObject elements are not sorted in order of increasing counter size. The following is a link to the website where I found the bubblesort algorithm. Thnaks a lot, Joe

http://linux.wku.edu/~lamonml/algor/sort/bubble.html
15 years ago
cheers Jess
15 years ago
Hi there. It has to be said that this is a great forum for java queries but I was wondering does anybody know of any quality maths forums out there or is there anywhere on this site to post maths type queries. I am having difficulty finding a decent maths forum. Thanks a lot Joe
15 years ago
Hiya Joe. Cheers for the response. I am going to turn this query into a more general post. Is there a limit on the size of a datastream (in bytes) that you can send via a socket connection. I am kind of new to all this socket business so you will have to excuse my ignorance. I am under the impression after surfing the net that it is possible to send streams of up to 64kb at one go. However my application will hopefully send files of maybe 1mb or even more than that from a server to a client. Therefore, I presume that I will have to send 64kb segments, one by one, until the entire file has been transferred over the socket connection and then reassemble the segments at the client into a single file. If I am sending several segments, is it necessary to open and close connections for each 64kb transfer or can I maintain a single connection for the entire transfer? Thanks for your time and patience, Joe
15 years ago
Hi there. I am trying to transfer xml files via sockets from one machine (acting as server) to another (acting as client) which works perfectly for files under a certain size. However when I attempt to increase the size of the XML file I keep encountering various errors. At the moment my code is configured to parse thru a file and add each character to a StringBuffer and then transmit that StringBuffer to the client via the socket connection. This all works fine in theory until the file that is being transferred reaches a certain size. My code is as follows....ugly I know but it does sort of work!

PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
FileInputStream file = new FileInputStream(file1);
int c = 0;
try
{
while ((c = file.read()) != -1)
{
buffer.append( (char) c);
}
out.println(buffer.toString()); //this sends data to the client
}
catch(Exception e){
e.printStackTrace();
}

Can somebody please advise me on a better and more suitable approach to sending files via sockets. Thanks a lot, Joe
15 years ago