• Post Reply Bookmark Topic Watch Topic
  • New Topic

code or server problem ?

 
hesham katon
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All
I have many websites that working with jsp and servlets that were working without problems, and one day i had lot of problems in all sites, the web hosting company insists that it's code problem and i believe that code was working fine for 3 years so it must be server problem

but the strange thing is every site has different problem

this is example of one site of them : wantech.com.eg

i found out that problem happens in pages that access database

i tried to make the jsp code more clear and clear , and i put comments to discover where is the problem

this is one jsp

-------
i found out that the problem starts when i add this line :

connection = DriverManager.getConnection("jdbc:mysql://localhost/wantech1_COMPUTEROFFER?user=username&password=password");

just when run this page it keeps loading forever

if i put comment beofre this line , the page runs fine and prints "Hello 4"

here is the link of it with the same code above , sure i put the real username and password :
http://www.wantech.com.eg/computers/offers/hotoffer.jsp

is there problem with my code ? or it's server problem ?

Thank you all in advance

[BPSouther: Added code tags]
[ September 17, 2007: Message edited by: Ben Souther ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It could be a problem with your database.
It's always hard to tell when everything exists in one script.

If this were my issue, I'd start by moving the database into a separate class, and test it as a standalone, Java, command line program. This would allow me to separate the database debugging issues from the web server debugging issues.

If you do that, you can, instead of putting the dababase code back into a scriptlet, instanciate the bean from your JSP and call it's methods to get the results back. This leads to using an MVC (model, view, controller) architecture that will make your life much simpler in the future.
[ September 17, 2007: Message edited by: Ben Souther ]
 
hesham katon
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ben,

I am using MySql database running fine , and i can access it using phpMyAdmin

I really appreciate your advice, but i am not used to work with beans and MVC

so i don't understand exactly what i have to do with my code ?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have some MVC examples in our codebarn that you might want to look at.
There is also an MVC tutorial in our CattleDrive.

First, though, let's look at your JSP.
This might be the problem:



The <%! tag creates an instance variable.
Instance variables are shared by all requests to a JSP.
This means that, if you hit your page, you're going to create a connection, statement, and resultset object. If I hit your page before it's done reading from your result set, I'm going to try to use the same variables for my own query which will either screw up yours or cause mine to hang; or both.

For now, move all that code out of there and put it in the top of the next block (without the <%! tag.

See if that helps.
 
hesham katon
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ben

I will take a look at MVC , thanks alot

about my code

<%! just makes those variables public

so there is no difference in the results

any way , i tried to do as you tole me , i put all the code inside <% %>

but it still gives the same action

loading long time

http://wantech.com.eg/computers/offers/hotoffer.jsp
 
hesham katon
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
after long long time of loading
i get this message :

Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
--------------------------------------------------------------------------------

Apache/1.3.37 Server at www.wantech.com.eg Port 80
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you been able to get a simple "Hello, World" jsp running on that server?
I can see from the error message that you, your company, or your hosting company is running something behind The Apache Web Server, which, on its own can't serve up servlets and JSP.

Doing this would let you know if all the plumbing needed to run JSP is in order.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, now that it's blown up, you can reasonably expect to see something in your log files, have you started reading through those yet?
 
hesham katon
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes
Simple jsp files working fine without problems
 
hesham katon
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In fact i didn't see logs until you told me

i checked logs now

the last log file is: context_log.2007-09-11.log

and there is no files for days after that !
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does that query work in phpMyAdmin like that; with the back ticks around the table name?

 
hesham katon
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i put the select statement as comments
so , it's not executed

but i tried it anyway in phpMyAdmin , and it worked fine

the code now just like this :

<%@ page import="java.sql.*" %>

<%
Connection connection = null;
Statement statement;
String query;

ResultSet resultset
try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
connection = DriverManager.getConnection("jdbc:mysql://localhost/wantech1_COMPUTEROFFER?user=username&password=password");
}
catch(Exception e)
{
out.print(e);
}
%>
-----------
and if i made comment on the line :
// connection = DriverManager.getConnection("jdbc:mysql://localhost/wantech1_COMPUTEROFFER?user=username&password=password");

the page runs successfully

i am really thankful for your help

thank you so much

i wish we find a solution
 
hesham katon
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is last part of logs that i have :
---------------------------------------------
2007-09-11 17:31:15 StandardManager[/manager] IOException while saving persisted sessions: java.io.FileNotFoundException: /usr/local/jakarta/jakarta-tomcat-4.1.30/work/Standalone/www.wantech.com.eg/manager/SESSIONS.ser (No such file or directory)
java.io.FileNotFoundException: /usr/local/jakarta/jakarta-tomcat-4.1.30/work/Standalone/www.wantech.com.eg/manager/SESSIONS.ser (No such file or directory)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
at java.io.FileOutputStream.<init>(FileOutputStream.java:70)
at org.apache.catalina.session.StandardManager.unload(StandardManager.java:508)
at org.apache.catalina.session.StandardManager.stop(StandardManager.java:691)
at org.apache.catalina.core.StandardContext.stop(StandardContext.java:3688)
at org.apache.catalina.startup.HostConfig.checkWebXmlLastModified(HostConfig.java:610)
at org.apache.catalina.startup.HostConfig.run(HostConfig.java:854)
at java.lang.Thread.run(Thread.java:595)

2007-09-11 17:31:15 StandardManager[/manager] Exception unloading sessions to persistent storage
java.io.FileNotFoundException: /usr/local/jakarta/jakarta-tomcat-4.1.30/work/Standalone/www.wantech.com.eg/manager/SESSIONS.ser (No such file or directory)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
at java.io.FileOutputStream.<init>(FileOutputStream.java:70)
at org.apache.catalina.session.StandardManager.unload(StandardManager.java:508)
at org.apache.catalina.session.StandardManager.stop(StandardManager.java:691)
at org.apache.catalina.core.StandardContext.stop(StandardContext.java:3688)
at org.apache.catalina.startup.HostConfig.checkWebXmlLastModified(HostConfig.java:610)
at org.apache.catalina.startup.HostConfig.run(HostConfig.java:854)
at java.lang.Thread.run(Thread.java:595)

2007-09-11 17:31:15 WebappLoader[/manager]: Deploying class repositories to work directory /usr/local/jakarta/jakarta-tomcat-4.1.30/work/Standalone/www.wantech.com.eg/manager
2007-09-11 17:31:15 WebappLoader[/manager]: Deploy JAR /WEB-INF/lib/catalina-manager.jar to /usr/local/jakarta/jakarta-tomcat-4.1.30/server/webapps/manager/WEB-INF/lib/catalina-manager.jar
2007-09-11 17:31:15 WebappLoader[/manager]: Deploy JAR /WEB-INF/lib/commons-fileupload-1.0.jar to /usr/local/jakarta/jakarta-tomcat-4.1.30/server/webapps/manager/WEB-INF/lib/commons-fileupload-1.0.jar
2007-09-11 17:31:15 StandardManager[/manager]: Seeding random number generator class java.security.SecureRandom
2007-09-11 17:31:15 StandardManager[/manager]: Seeding of random number generator has been completed
2007-09-11 17:31:15 StandardWrapper[/manager:default]: Loading container servlet default
-------------------------------------------
I wish it may help

isn't it strange that no logs after 9/11 ???
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you put the driver's jar file?
 
hesham katon
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
this may be driver issue
I know that jar files should be put under WEB-INF/lib/

i found this folder empty

in fact i designed this site 3 years ago , and it was working like that since that time

i think it was calling drivers from the root of Tomcat

i tried not to upload

servlet.jar
jdbc2_0-stdext.jar

but it stil doesn't work

what do you think ?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know.
Usually when the driver can't be found, things come to a quick halt and the logs will say so. The JDBC driver jar file would work in WEB-INF/lib, tomcat/common/lib, or tomcat/shared/lib with your code.

Could it be that the database has been upgraded and is no longer compatible with the driver you've got?

I'm out of ideas but, since you've narrowed it down to the line that obtains the database connection, you might want this thread moved to our JDBC forum.
Someone there might have smarter questions to ask than I do.

Let me know and I'll move it for you.
-Ben
 
hesham katon
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes , i feel more and more that it's driver problem
I am tryint to download the right jdbc driver

but is it must to restart tomcat after putting it under WEB-INF/lib ?

I am really thankful

i wish this works
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by hesham katon:
but is it must to restart tomcat after putting it under WEB-INF/lib ?
You must restart the web app. There is no need to restart all of tomcat.
 
hesham katon
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works finally

I dont know how to thank you sooooo much

In fact i dont know how to restart webapp only ?
this application is hosted in shared hosting company
and i just ask them to restart Tomcat !

I will move to fix other jsp websites tomorrow

I wish it will be the same problem

Thank you again very very much
 
hesham katon
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

it worked for few minutes
and now it's back loading for long time again
 
indika prasad kularathne
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..
This could be the database connection problem. I had a same problem for mysql. The issue is here; you are not using the connection pooling. so every time page get loaded, it will create a new connection. It might works for some time until number of connections allowed is exceeded. Then it won't give any response.
Refer tomcat connection pooling in tomcat help file. And based on that write you database connection string...etc. then problem will be ok.

Thanks
Indika Prasad
 
hesham katon
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it's a database error , and i will move this topic to JDBC

Thank you all
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by indika prasad kularathne:
Hi..
This could be the database connection problem. I had a same problem for mysql. The issue is here; you are not using the connection pooling. so every time page get loaded, it will create a new connection. It might works for some time until number of connections allowed is exceeded. Then it won't give any response.
Refer tomcat connection pooling in tomcat help file. And based on that write you database connection string...etc. then problem will be ok.

Thanks
Indika Prasad



This is a good point.
You might not be ready to switch over to connection pooling yet but you should change your code to insure that the connection is closed in a finally block.

If, for some reason your connections aren't being closed properly, your app will force Mysql to keep generating new ones. Eventually, it will hit its limit. This could be what is causing your app to stall. Mysql might be waiting for a connection to be released before handing your app a new one.
 
hesham katon
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in fact i am sure to close every connection at the end of the code by :
connection.close();

now the driver is running under WEB-INF\lib

and the site worked yesterday for few minutes

then the problem back again
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!