Home arrow static arrow Java Programming [Archive] - is it possible?A computer, inconsistant?
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - is it possible?A computer, inconsistant?
This topic has 18 replies on 2 pages.    1 | 2 | Next »

Posts:343
Registered: 7/13/04
is it possible?A computer, inconsistant?  
Jul 26, 2004 4:10 PM



 
my gosh, i'm using eclipse, jdk 1.4.2 blablabla,
check this out!
when I run my program, it goes through a loop and throws data into a database, BUT the last time through the loop it fails to "throw" the data into the database. I thought this odd, so i went through line by line, trying to see what went wrong, and it read the code just fine the last time through, just to check, i look at my database and sure enough the information is there.

summary: when i run my program normally, it fails to execute my sql commands on the last time throug hthe loop, but does everything just as i want it to when i debug it going line by line.

anyone ever heard of such a thing?
 

Posts:37,103
Registered: 3/30/99
Re: is it possible?A computer, inconsistant?  
Jul 26, 2004 4:14 PM (reply 1 of 18)



 
anyone ever heard of such a thing?

Yep--when assumptions I'm making about what's going on are wrong.
 

Posts:343
Registered: 7/13/04
Re: is it possible?A computer, inconsistant?  
Jul 26, 2004 4:19 PM (reply 2 of 18)



 
is there any way to figure out what is really going on besides using the debugger and going line-by-line?
 

Posts:2,830
Registered: 9/1/03
Re: is it possible?A computer, inconsistant?  
Jul 26, 2004 4:22 PM (reply 3 of 18)



 
is there any way to figure out what is really going on
besides using the debugger and going line-by-line?

I have a physic I call up when I am really lost, it generally works
quite well, recently I found out that my computer will meet a tall
dark stranger and marry him, unforunately this stranger will then
cheat on my computer with my fax machine :(
 

Posts:343
Registered: 7/13/04
Re: is it possible?A computer, inconsistant?  
Jul 26, 2004 4:24 PM (reply 4 of 18)



 
hehehe, well, i guess the only solution i can think of is do the same thing a different way. (and keep doing it a different way until it works) :)
 

Posts:37,103
Registered: 3/30/99
Re: is it possible?A computer, inconsistant?  
Jul 26, 2004 4:32 PM (reply 5 of 18)



 
is there any way to figure out what is really going on
besides using the debugger and going line-by-line?

logging--either with println or with something like log4j.

Is there any multithreading going on here?

Can you post some code? Not the whole thing, just the relevant portions.
 

Posts:343
Registered: 7/13/04
Re: is it possible?A computer, inconsistant?  
Jul 26, 2004 4:48 PM (reply 6 of 18)



 
no multithreading whatsoever, here is some code to chew on (i eliminated almost all the code. these are what i think are the important parts. if you want something specific to look (one of the classes referenced) at just tell me
        //continue process of reading and sorting messages and fields until file is over		while (ReadData.eof) {	 		     byte [] array = null;     // some unimportant stuff here (reading/retrieval/storage of data)         try {            array = ReadData.ReadMessage(in);  // read each message and store in byte array: array. (when message is over sets variable: eof to false)                        sql.ins("INSERT INTO FrameData (" +        			"FrameNumber, MessageId, PlatformId, TaskId, ParentId, TimeOfDay" +        			") VALUES (" +        			 frame + "," +        			 mid + "," +        			 pid + "," +        			 tid + "," +        			 paid + "," +        			 day + ")");        }catch (EOFException error) {      	return; // all done reading messageX      }	}		in.close();	// all done reading file -------------------------------------sql.ins class----------------------------------------------------	  public void ins(String sql) throws Exception {	    Statement stmt = null;	    if (dbConn == null)	      throw new Exception("No database connection");	    try {	       stmt = dbConn.createStatement();	       stmt.executeUpdate(sql);	     } catch (Exception error) {	       System.out.println(error);	     }	  }
 

Posts:343
Registered: 7/13/04
Re: is it possible?A computer, inconsistant?  
Jul 26, 2004 4:50 PM (reply 7 of 18)



 
by the way, i tried the: println("DLSKF");
idea, and it didn't help, because it printed everything, even the times i put it all up in the ins class.
its really confussing.
 

Posts:8,813
Registered: 10/4/00
Re: is it possible?A computer, inconsistant?  
Jul 26, 2004 4:53 PM (reply 8 of 18)



 
}catch (EOFException error) {      	error.printStackTrace();  //  !!!!!!!!!!!!      	return; // all done reading messageX      }
 

Posts:8,813
Registered: 10/4/00
Re: is it possible?A computer, inconsistant?  
Jul 26, 2004 4:56 PM (reply 9 of 18)



 
Actaully, somewhere you must be catching the exception you throw from ins(). Do you throw that one away too?
 

Posts:343
Registered: 7/13/04
Re: is it possible?A computer, inconsistant?  
Jul 26, 2004 4:57 PM (reply 10 of 18)



 
nope, didn't help
 

Posts:343
Registered: 7/13/04
Re: is it possible?A computer, inconsistant?  
Jul 26, 2004 4:57 PM (reply 11 of 18)



 
hmmm, dont know if i catch all the exceptions, i'll look into it
 

Posts:37,103
Registered: 3/30/99
Re: is it possible?A computer, inconsistant?  
Jul 26, 2004 5:00 PM (reply 12 of 18)



 
Make sure you're explicitly closing your Statement in a finally block. Also, you may want to try an explicit commit, though I thought the default was to autocommit.
 

Posts:343
Registered: 7/13/04
Re: is it possible?A computer, inconsistant?  
Jul 26, 2004 5:02 PM (reply 13 of 18)



 
i never close my statement, because from what i read, i thought it automatically closes eventually, and yes, autocommit is the default (though i've put it in there and taken it out to see if it makes a difference and it doesn't)
 

Posts:37,103
Registered: 3/30/99
Re: is it possible?A computer, inconsistant?  
Jul 26, 2004 5:06 PM (reply 14 of 18)



 
i never close my statement, because from what i read,
i thought it automatically closes eventually

Don't rely on that. Also, like bbritta said, make sure you're not smothering any exceptions. Always print the stack trace.

Are you saying that you put a print statement in after the call to stmt.executeUpdate and it printed out, indicated that update executed the expected number of times? If so, then it's almost certainly a commit or close issue or an exception being smothered.
 
This topic has 18 replies on 2 pages.    1 | 2 | Next »