Meaningless Drivel is fun!
The moose likes JDBC and Relational Databases and the fly likes ODBC - mysql connectivity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "ODBC - mysql connectivity" Watch "ODBC - mysql connectivity" New topic

ODBC - mysql connectivity

Jysh Reey

Joined: Oct 10, 2011
Posts: 16

Here i hav enclosed my Java program that has mysql as backend...

am using ubuntu... when i press connect button after specifying the details, in Mysql Administrator, it displays the server is running... this java prog of mine is complied and is without any error... but when i type java -cp .:/usr/share/java/mysql-connector-java-5.1.10.jar Test in terminal i receive the following error.....!!

Enter a date:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

my sql table description:

could not find whats wrong with the connection..... somebody please help...
due to this my college project is in stagnate condition...

Tim Moores

Joined: Sep 21, 2011
Posts: 2409
At which point does ODBC (which the subject talks about) come into play?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15033

Welcome to the Ranch.

By default, MySQL does not allow access from remote computers. If your MySQL server is running on a different computer then where you are running your program on, then you have to enable remote connections on the MySQL server.

In line 20 of your code, try using "localhost:3306" instead of "jeyasri-desktop:3306". When you specify an explicit hostname ("jeyasri-desktop") then MySQL might treat it as a remote connection and deny it.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Rob Spoor

Joined: Oct 27, 2005
Posts: 20180

It most certainly will. The MySQL user table has a column for the host that the connections can come from. Sometimes there is a catch-all there, but by default Ubuntu only has "localhost" for the root user. If the connecting host does not equal one of the allowed host for the user, and there's no catch-all, then you simply will not be able to connect.

I'll move this thread to our JDBC forum.

How To Ask Questions How To Answer Questions
Jysh Reey

Joined: Oct 10, 2011
Posts: 16
First of all thanks for everyone who made a response..

@Tim Moores : Am sorry, its JDBC...

@Jesper de Jong, @Rob Spoor : No am running Mysql in the same computer... i have created a connection in the Mysql Administrator with the host name "jeyasri-desktop"... changing it into localhost also results the same... i once read in a forum that the IP address may also be a problem for said there are case where the default IPaddress to be while creating connection Mysql Administrator showed the IP address as am i supposed to set this somewhere ?
I agree. Here's the link:
subject: ODBC - mysql connectivity
It's not a secret anymore!