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

Problems between Java and MySQL in Debian

0 views
Skip to first unread message

Alejandro Muñoz

unread,
Jan 6, 2004, 12:58:57 PM1/6/04
to
Hello all,

I use JDK 1.4.1 and MySQL 3.23. In a program in Java that I am
developing I use a MySQL database. For the communication between both I
use driver (package jar in fact) that provides the MySQL site
(www.mysql.com) denominated Connector/J. For the connection I use the
examples of that package.
In RedHat 9 and Windows XP/98 everything goes well and everything works,
but not in Debian. In fact, separately, Java and MySQL works well. I
connect to databases throw mysql client (command line) and even from
PhpMyAdmin without problems. But my program can't connect to it.
Moreover, JavaMyAdmin can't connect to it too.
In /etc/services Mysql has the port 3306 and the daemon mysqld is running.
¿Does Java Driver work well in Debian? ¿Someone help me?

In the graphical processes manager (I am not administrator in those
hosts) appears mysqld with the following parameters:
/usr/sbin/mysqld --basedir=/usr/ --datadir=/var/lib/mysql --user=mysql
--pid-file=/var/lib/mysql/hostname.pid --skip-locking

Thanks in advance.

Chris Smith

unread,
Jan 6, 2004, 1:37:29 PM1/6/04
to
Alejandro Muñoz wrote:
> In RedHat 9 and Windows XP/98 everything goes well and everything works,
> but not in Debian. In fact, separately, Java and MySQL works well. I
> connect to databases throw mysql client (command line) and even from
> PhpMyAdmin without problems. But my program can't connect to it.
> Moreover, JavaMyAdmin can't connect to it too.

Maybe you should expand on what you mean by "can't connect to it". What
error message do you get?

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Alejandro Muñoz

unread,
Jan 6, 2004, 2:49:49 PM1/6/04
to
Chris Smith wrote:
> Alejandro Muñoz wrote:
>
>>In RedHat 9 and Windows XP/98 everything goes well and everything works,
>>but not in Debian. In fact, separately, Java and MySQL works well. I
>>connect to databases throw mysql client (command line) and even from
>>PhpMyAdmin without problems. But my program can't connect to it.
>>Moreover, JavaMyAdmin can't connect to it too.
>
>
> Maybe you should expand on what you mean by "can't connect to it". What
> error message do you get?
>

"Can't connect to it":

Connection conn=null;
//Registramos el driver
Class.forName("com.mysql.jdbc.Driver").newInstance();
//Conexión a la BD
conn=DriverManager.getConnection
("jdbc:mysql://"+host+"/"+database+"?user="+user+"&password="+password);


The sentence getConnection throw an exception:

java.sql.SQLException: Cannot connect to MySQL server on hostname:3306.
Is there a MySQL server running on the machine/port you are trying to
connect to? (java.net.ConnectException)
at com.mysql.jdbc.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.jdbc2.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.Driver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:193)


But, mysqld is listening in port 3306 because the configuration of
port in the PhpMyAdmin is set to 3306 and "mysql --port 3306 -u user
..." works well.
Because that, ¿can java driver work wrong in debian?

Sudsy

unread,
Jan 6, 2004, 2:57:52 PM1/6/04
to
Alejandro Muñoz wrote:
> java.sql.SQLException: Cannot connect to MySQL server on hostname:3306.
> Is there a MySQL server running on the machine/port you are trying to
> connect to? (java.net.ConnectException)

This tells you the problem: you haven't specified the hostname
correctly. The driver is trying to connect to a host by the name
of "hostname". If you're running the client on the same machine
as the MySQL servers then try either "localhost" or "127.0.0.1"
(the loopback interface).

Alejandro Muñoz

unread,
Jan 6, 2004, 4:48:16 PM1/6/04
to

Unfortunately with localhost it does not work either, already had proven it.

newsadict

unread,
Jan 6, 2004, 5:45:11 PM1/6/04
to
I think, it should be something like this:

String url ="jdbc:mysql://localhost:3306/"+tablename; // tablename = folder
name in your mysql/data folder
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url,
user,
password);
}
catch (ClassNotFoundException exc) {
System.out.println("blah-blah");
close();
}
catch (SQLException exc) {
System.out.println("SQL-blah-blah");

close();
}
catch (Exception e) {

System.out.println("Something not Class or SQL blah-blah");
close();
}

"Alejandro Muñoz" <am...@eresmas.com> wrote in message
news:woEKb.328807$Ip6.6...@news-reader.eresmas.com...

0 new messages