aspose file tools*
The moose likes JDBC 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
Bookmark "ODBC - mysql connectivity" Watch "ODBC - mysql connectivity" New topic
Author

ODBC - mysql connectivity

Jysh Reey
Greenhorn

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:

2001-2-3
2001-02-03
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
Rancher

Joined: Sep 21, 2011
Posts: 2408
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: 14274
    
  21

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
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jysh Reey
Greenhorn

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 it..it said there are case where the default IPaddress to be 127.0.0.1... while creating connection Mysql Administrator showed the IP address as 192.168.1.2... am i supposed to set this somewhere ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ODBC - mysql connectivity