Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
java.net.BindException errors

Posted by redstar (redstar), 11 January 2005
Hi

I am developing a java/MySql client server application
I am well advanced with it but have come to a stop caused by the error message below.

The class being run holds fairly simple embedded sql commands that return a value. There may be several hundred calls to the various methods. The method seems to arise in no particular place in the program.
Any suggestion where to start looking would be a great help. I tried closing all the connections once used

a typical method is as follows
public int getShiftDownTime(String date1,String date2,String Shift){

int ShiftDownTime=0;
try{
SetConnectionDT setConShiftDown = new SetConnectionDT();

Connection tcShiftDown=setConShiftDown.getConnectionDT();

Statement stmtShiftDown= tcShiftDown .createStatement();

ResultSet rsShiftDown=null;

String sql8="Select sum(DTElapsedMins),DTDate from downtimelinedata where DTDate between "+ "'" + date1 + "' and "+"'"+date2+"'"+" and STNum ="+"'"+Shift+"'"+" group by DTDate";

System.out.println("getShiftDownTime"+sql;
rsShiftDown=stmtShiftDown.executeQuery(sql;
tcShiftDown.close();

while(rsShiftDown.next()){
   ShiftDownTime=ShiftDownTime+rsShiftDown.getInt(1);
   }
   rsShiftDown.close();
}
catch (SQLException sqe){
   System.out.println(sqe);
}
if(ShiftDownTime>60){
ShiftDownTime=(int)(ShiftDownTime/60);
return ShiftDownTime;
}
else{
return 0;
}

}

//error message

connection problemjava.sql.SQLException: Unable to connect to any hosts due to exception: java.net.BindException: Address in use: no further information

Exception occurred during event dispatching:

java.lang.NullPointerException
     at coriolis1_1b.Ops_Rep_Top.getShiftRunTime(Ops_Rep_Top.java:5772)

     at coriolis1_1b.Ops_Rep_Top.loadTable(Ops_Rep_Top.java:1666)

     at coriolis1_1b.Ops_Rep_Top.<init>(Ops_Rep_Top.java:79)

     at coriolis1_1

Posted by admin (Graham Ellis), 11 January 2005
Hello - been looking to see what I can see here.  I understand that the problem is intermittent - in other words that it occurs at different times / points even if you run the same query a number of times?

The method that you've provided as an example is getShiftDownTime, but the error message example is getShiftRunTime.  I do understand that they're probably very similar, but if you could post the source of the method that exceptioned, it might be useful.  Could you also tell us which is line 5772.

As an educated guess, there's some sort of timing issue here. As a first step to debugging, I would catch the exception and look at the exception object.  As a second step, I would look at using a single thread model - perhaps not as a permanent fix, but to help with the analysis.

Posted by redstar (redstar), 12 January 2005
Hi Graham
Thanks for your comments. Since our last exchange I have reduced the size of my program so that it is only generating a few rows on the jTable. I have got to a point where I can run the the same report 5 times in succession with the same date parameter and on the fifth (or so) attempt it will crash. The row numbers referred to in every crash point to a line of code where a 'Statement 'is created  Also once it has crashed I need to recompile before the program will run again(sometimes even reboot)

example line where crash is identified
Statement stmtAveCo = tcAveCo .createStatement();

I have maybe 20 methods to create the report/jtable and some of these methods may be called 8 times for different date ranges. Is it acceptable to define a single 3 part connection statement at the beginning of my report and to keep reusing it for each method call so that I am using only one connection. All I would then do is vary the resultset name, and I could possibly again keep reusing the same name?

the error message for this statement was

connection problemjava.sql.SQLException: Unable to connect to any hosts due to exception: java.net.BindException: Address in use: no further information

Exception occurred during event dispatching:
java.lang.NullPointerException      at coriolis1_1b.Ops_Rep_Top.getAveChangeoverTime(Ops_Rep_Top.java:5266) at coriolis1_1b.Ops_Rep_Top.loadTable Ops_Rep_Top.java:61 at coriolis1_1b.Ops_Rep_Top.<init>(Ops_Rep_Top.java:79)
at coriolis1_1b.CorMFrame.jMenuItem35_actionPerformed(CorMFrame.java:205
etc..........
the whole method and its calling statement is
//calling the method from
aveChange=getAveChangeoverTime(date9,date10);

//storing the result in an array-jtable
data [rowCount][8]=df2.format(aveChange);

//method
public int getAveChangeoverTime (String date1,String date2){
String sql="";
int aveSet=0;
int totTime=0;
int totNumSets=0;

try{
SetConnectionDT setConAveCo = new SetConnectionDT();//dates
Connection tcAveCo = setConAveCo.getConnectionDT();
Statement stmtAveCo = tcAveCo .createStatement();


String code="Product Changeover";
//note that the next statement is not as coded but is a copy of the sql line created by the program

String sql="select DTDate,sum(DTElapsedMins),count(*) from downtimelinedata where DTCodeNum= 'Product Changeover' and DTDate between '2004-09-26' and '2004-08-30'  group by DTDate";


ResultSet rsAveCo=stmtAveCo.executeQuery(sql);
tcAveCo.close();
while(rsAveCo.next()){
totTime=totTime+rsAveCo.getInt(2);
totNumSets=totNumSets+rsAveCo.getInt(3);
}
if(totNumSets>0){
aveSet=(int)(totTime/totNumSets);
}
rsAveCo.close();
}
catch (SQLException sqe){
 System.out.println(sqe);
}
return aveSet;


}

Hope you can help me on this Graham as its driving me mad.

ps thanks for returning my pad.


Best Regards
Bernard





Posted by admin (Graham Ellis), 13 January 2005
Oh help!  This needs a bit longer to look at than I have at this brief visit to "Opentalk"; I'll come back with a fuller look later.

I did notice:

Quote:
Also once it has crashed I need to recompile before the program will run again(sometimes even reboot)


And that tells me that it's something to do with caching connections not being released (or similar);  once you recompile, your application server is forced to reload the application as it thinks the code has changed and thus releases the resource that's causing the issue  

What are you hosting on?  Linux or Unix box?? Just as a matter of interest, touch the .class file when you get a problem and see if this re-timestamping lets you run another 5 queries  

Posted by redstar (redstar), 13 January 2005
Hi Graham

I bit more information

I copied the database and software onto my laptop and it ran without a fault?

The database is on a Windows server

Sorry to lumber you with such a weighty problem first time around, but I can't seem to get over it.

Regards
Bernard

Posted by redstar (redstar), 13 January 2005
Hi Graham

I'm making a bit of progress. I found a website that suggested the following

//////////////////////////////////////////////////////////////////////
This is a problem of the used sockets with Windows NT. You can request the active sockets with the command netstat. The problem is a function of:

MaxUserPort (default 5000)
KeepAliveTime (default 120)
////////////////////////////////////////////////////////////////////
it suggested the workaround was connection pooling

I have run netstat to look at the number of connections when the problem occurs and waited for the timeout to reset the os back to the minimum and on each occasion my report has run

Does this sound logical?
If so

do you have any examples on connection pooling

Best Regards
Bernard



Posted by Custard (Custard), 13 January 2005
Hi,

Not sure how much help this will be, but on this very site, there is a post by myself relating to another question, but the example is of connection pools.

http://www.wellho.net/cgi-bin/opentalk/YaBB.pl?board=java;action=display;num=1068719223

HTH

B



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho