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.
<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
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>,
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.
>
...
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>,