Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

java, mm.mysql - Netowrk Unreachable error?

3 views
Skip to first unread message

maw6...@my-deja.com

unread,
Jul 26, 2000, 3:00:00 AM7/26/00
to
Greetings jdbc gurus,
I am trying to move some perl DBI code that
accesses a mysql server over to java. So I
downloaded the mm.mysql jdbc drivers and put them
in my classpath. Then I made a simple program
from the docs just to test the connection.

Here is the code (formatting looks weird in thsi
box, hope it comes out well in post):

import java.sql.*;

public class mysqltest {
public static void main(String[] Args) {
try {
Class.forName
("org.gjt.mm.mysql.Driver").newInstance();
}
catch (Exception E) {
System.err.println("Unable to load
driver.");
E.printStackTrace();
}
try {
Connection C = DriverManager.getConnection
("jdbc:mysql://localhost/testdb", "user", "pass");
//DriverManager.getConnection
("jdbc:mysql://localhost/testdb?
user=user&password=pass"); tried it this way as
well
}
catch (SQLException E) {
System.out.println("SQLException: " +
E.getMessage());
System.out.println("SQLState: " +
E.getSQLState());
System.out.println("VendorError: " +
E.getErrorCode());
}
}
}

When I try to run this on the linux box with the
mysql satabase I get the following:

java.io.IOException: Network is unreachable
at java.net.PlainSocketImpl.connect
(PlainSocketImpl.java:56)
at java.net.Socket.<init>(Socket.java:55)
at java.net.Socket.<init>(Socket.java:31)
at org.gjt.mm.mysql.MysqlIO.<init>
(MysqlIO.java:114)
at org.gjt.mm.mysql.Connection.<init>
(Connection.java:229)
at org.gjt.mm.mysql.Driver.connect
(Driver.java:126)
at java.sql.DriverManager.getConnection
(DriverManager.java:61)
at java.sql.DriverManager.getConnection
(DriverManager.java:49)
at mysqltest.main(mysqltest.java:15)
SQLException: Cannot connect to MySQL server on
localhost:3306. Is there a MySQL server running
on the machine/port you are trying to connect to?
(java.io.IOException)
SQLState: 08S01
VendorError: 0

This is strange because there IS a mysql server
running on this box and it is set to the default
port of 3306. I have PhP set up on this box as
well and it is able to access the database fine,
as is my perl code.

I also tried to run this test program from a
Win98 command sheel on the network with the linux
server. There is get the following output:

SQLException: Server configuration denies access
to data source
SQLState: 08001
VendorError: 0

This leads me to believe that it si connecting
from the Win98 but does not have permission since
it is not coming from localhost.

I also tried to have the linux box use it's ip
instead of localhost and got this output:


java.io.IOException: No buffer space available
at java.net.PlainSocketImpl.connect
(PlainSocketImpl.java:56)
at java.net.Socket.<init>(Socket.java:55)
at java.net.Socket.<init>(Socket.java:31)
at org.gjt.mm.mysql.MysqlIO.<init>
(MysqlIO.java:114)
at org.gjt.mm.mysql.Connection.<init>
(Connection.java:229)
at org.gjt.mm.mysql.Driver.connect
(Driver.java:126)
at java.sql.DriverManager.getConnection
(DriverManager.java:61)
at java.sql.DriverManager.getConnection
(DriverManager.java:49)
at mysqltest.main(mysqltest.java:15)
SQLException: Cannot connect to MySQL server on
10.10.10.22:3306. Is there a MySQL server running
on the machine/port you are trying to connect to?
(java.io.IOException)
SQLState: 08S01
VendorError: 0

Well, that is my problem. I am not sure where to
go from here. I assume it is some setup or
config problem on my linux box. Does anyone
recognize this problem and/or have any idea how I
can fix it? For now I guess I will try the twz
jdbc drivers and see if I have more luck.

Thanks for any help you can give me,
Adidos,
Matt Weaver


Sent via Deja.com http://www.deja.com/
Before you buy.

Nicolas Delbing

unread,
Jul 26, 2000, 3:00:00 AM7/26/00
to
you forgot to specify the port for getConnection - it should be
"jdbc:mysql://localhost:3306/testdb"


<maw6...@my-deja.com> skrev i en
nyhedsmeddelelse:8ln2h3$p0m$1...@nnrp1.deja.com...


> Greetings jdbc gurus,
> I am trying to move some perl DBI code that
> accesses a mysql server over to java. So I
> downloaded the mm.mysql jdbc drivers and put them
> in my classpath. Then I made a simple program
> from the docs just to test the connection.
>
> Here is the code (formatting looks weird in thsi
> box, hope it comes out well in post):
>
> import java.sql.*;
>
> public class mysqltest {
> public static void main(String[] Args) {
> try {
> Class.forName
> ("org.gjt.mm.mysql.Driver").newInstance();
> }
> catch (Exception E) {
> System.err.println("Unable to load
> driver.");
> E.printStackTrace();
> }
> try {
> Connection C = DriverManager.getConnection
> ("jdbc:mysql://localhost/testdb", "user", "pass");

> file://DriverManager.getConnection

maw6...@my-deja.com

unread,
Jul 26, 2000, 3:00:00 AM7/26/00
to
Oh, I thought the port was optional if you were using the default
3306. I went head and added that in but nothing changed. I still get
the Network is Unreachable error. How can localhost be unreachable?

I tried out the twz drivers and I get the same error with them. Not
really sure how to go about debugging this error. Any ideas are
greatly appreciated.

Thanks,
Matt


In article <rOFf5.262$DK....@news101.telia.com>,

Sven Coenye

unread,
Jul 26, 2000, 3:00:00 AM7/26/00
to
This is usually because Linux can't resolve localhost. Try ping
localhost and see what happens. If ping can't resolve localhost, add
127.0.0.1 localhost to /etc/hosts and try the JDBC code again.

I've had my /etc/hosts file run over a couple of times for unknown
reasons, although I suspect linuxconf. The result is usually identical
to your problem.

Unfortunately, this won't solve the "Connection denied" problem :-( I'm
not sure what's causing that (trying to resolve the same problem on my
end right now ...)

maw6...@my-deja.com wrote:
>
> Greetings jdbc gurus,
> I am trying to move some perl DBI code that
> accesses a mysql server over to java. So I
> downloaded the mm.mysql jdbc drivers and put them
> in my classpath. Then I made a simple program
> from the docs just to test the connection.
>

...

Pavel Drab

unread,
Aug 1, 2000, 3:00:00 AM8/1/00
to
Which version of mm.mysql driver are you using.
Try the last one.
Paul
<maw6...@my-deja.com> píąe v diskusním příspěvku
news:8ln2h3$p0m$1...@nnrp1.deja.com...

> Greetings jdbc gurus,
> I am trying to move some perl DBI code that
> accesses a mysql server over to java. So I
> downloaded the mm.mysql jdbc drivers and put them
> in my classpath. Then I made a simple program
> from the docs just to test the connection.
>
> SQLException: Cannot connect to MySQL server on
> localhost:3306. Is there a MySQL server running
> on the machine/port you are trying to connect to?
> (java.io.IOException)
> SQLState: 08S01
> VendorError: 0
>
> SQLException: Cannot connect to MySQL server on
> 10.10.10.22:3306. Is there a MySQL server running

> on the machine/port you are trying to connect to?
> (java.io.IOException)
> SQLState: 08S01
> VendorError: 0
>

gshi...@my-deja.com

unread,
Aug 3, 2000, 3:00:00 AM8/3/00
to
Hmm... weird. I did have some problem earlier in the week with being
able to connect to any database other than the test database. Try
connection to that database first.

A few things to consider (assuming you can ping localhost):

Did you configure MySQL with username and passwords? If so, you will
need to grant the user right with a statement like
'GRANT ALL ON databas_name.* TO user@hostname IDENTIFIED BY "password";

eg, if I wanted to create a user gshipley with a password of 'linux123'
and give him access to the mp3 database from any host at linux.com I
would type the following:

GRANT ALL on mp3.* TO gshipley@%.linux.com IDENTIFIED BY "linux123";

Following is some sample code to test the jdbc connection. You do not
need to authenticate to use the test database.


--- cut here ---
//This source file will create a database connection to mysql
//This source file serves no purpose whatsoever, other than to test JDBC

import java.sql.*;
import java.io.*;

// Notice, do not import org.gjt.mm.mysql.*
// or you will have problems!

public class LoadDriver


{
public static void main(String[] Args)
{
try {

Class.forName("org.gjt.mm.mysql.Driver").newInstance();

}
catch (Exception E) {
System.err.println("Unable to load driver.");
E.printStackTrace();
}

try {
Connection C = DriverManager.getConnection(

"jdbc:mysql://localhost:3306/test");
C.close();


}
catch (SQLException E) {
System.out.println("SQLException: " + E.getMessage());
System.out.println("SQLState: " + E.getSQLState());
System.out.println("VendorError: " + E.getErrorCode());
}

System.out.println("able to connect");
}}


--- end cut ---

Grant Shipley
Java Developer / Caldera Systems


In article <fqv5m8...@128.10.1.254>,

0 new messages