Problems between Java and MySQL in Debian

  • Thread starter =?ISO-8859-1?Q?Alejandro_Mu=F1oz?=
  • Start date
?

=?ISO-8859-1?Q?Alejandro_Mu=F1oz?=

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

Chris Smith

Alejandro said:
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
 
?

=?ISO-8859-15?Q?Alejandro_Mu=F1oz?=

Chris said:
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?
 
S

Sudsy

Alejandro said:
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).
 
?

=?ISO-8859-15?Q?Alejandro_Mu=F1oz?=

Sudsy said:
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).

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

newsadict

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();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,097
Latest member
RayE496148

Latest Threads

Top