• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

JSP and MySql

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Neha Ashok
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic