jQuery in Action, 3rd edition
The moose likes JSP and the fly likes JSP and MySql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP and MySql" Watch "JSP and MySql" New topic

JSP and MySql

Neha Ashok

Joined: Dec 12, 2002
Posts: 26
While I'm attempting to connect to MySQl from my JSP (bean) I get the following error :
"java.sql.SQLException Communication link failure :Band handshake "
My environment: Windows 2000, JDK1.3.1, MySQL. The servlet container is JSDK2.1. The JDBC driver is mm.mysql-2.0.4-bin.jar.
con = DriverManager.getConnection(
Can anyone reply immediately please?
Tina Coleman
Ranch Hand

Joined: Dec 12, 2001
Posts: 150
According to the mySQL documentation, the Bad handshake exception occurs if the mysqld times out before getting a connect packet. Thus it seems that you've got the driver in the path appropriately, and that the system is able to find the mysqld, though it may not be able to find your specific database.
Things worth checking:
* does your JDBC connection string work outside of the servlet/JSP environment? Can you make a connection from some test code using that string?
* if you're still getting a timeout, can you reset the connect-timeout to a higher value and then get a connection?

Something else worth considering, particularly if you are able to connect outside of a servlet environment: mySQL has a username/host setup within its user tables. Presumably, the web server system host may be different than the general system host. Verify that the username/hoset setup within the database user tables isn't foobarring you.
Wish I had a specific fix-it kind of answer, but hopefully one of these checks will lead you either down an immediately right path, or will get you some more information.
Juanjo Bazan
Ranch Hand

Joined: Feb 04, 2002
Posts: 231
Make sure a mysql server instance is running in your computer.
MySql default port is 3306.
If you have not change it, your url should be:
Neha Ashok

Joined: Dec 12, 2002
Posts: 26
Thanks to both of you. I've resolved this problem .
a) I have not changed the port number and it is still the default one.
b) Class is getting loaded , so there fore there could be no problem with the path.
c)Last thing was,when I tried to connect from a stand -alone java program and it gave me the same error "Communication link failure Bad handshake".
After hunting a little while in the net , I found this solution from:
Have cleared it now.
Thanks all

Corrected the URL link. Removed the "." char at the end of the URL.
- madhav
[ January 17, 2003: Message edited by: Madhav Lakkapragada ]
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Now that everything works and before you move on to better busier things, I have a few suggestions:
Move your conectin code and the stuff that deals with the DB to a bean. You already seem to have a "standalone" program from which you got the same error. A Java bean, as you may know if nothing different from a standalone Java program.
I personally (and that's just me) don't favor DB code in JSP/Servlet code.
Secondly, if you have the power to change, move on to using something newer than the The servlet container is JSDK2.1 stuff.
Just some friendly suggestions....
- madhav

Take a Minute, Donate an Hour, Change a Life
I agree. Here's the link: http://aspose.com/file-tools
subject: JSP and MySql
It's not a secret anymore!