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( "jdbc:mysql://localhost/test?user=root&password=root"); Can anyone reply immediately please?
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.
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: "jdbc:mysql://localhost:3306/test?user=root&password=root" HTH
Joined: Dec 12, 2002
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: http://otn.oracle.com/support/tech/migration/workbench/htdocs/bulletins/mysql_01.htm Have cleared it now. Thanks all
ps: Corrected the URL link. Removed the "." char at the end of the URL. - madhav [ January 17, 2003: Message edited by: Madhav Lakkapragada ]
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