List:MySQL and Java« Previous MessageNext Message »
From:Christian Mack Date:July 20 1999 8:15pm
Subject:Re: cannot connect to mysql
View as plain text  
Paal Are Solberg wrote:
> 
> Trying to get started on java applications and jdbc...but I'm having trouble
> with the basics. Can anyone help me over these initial hurdles?
> 
> Client running NT 4.0.
> Mysql 3.22.21 up and running on Linux on the machine 'dbserver'
> 
> On the client I try this:
> 
> C:\>C:\jdk1.1.7B\bin\javac -classpath
> C:\jdk1.1.7B\lib\classes.zip;C:\mm\mm.mysql.jdbc.1.1f\mysql.jar testfile.java
> 
> -this compiles; I try to run the class file :
> 
> C:\>C:\jdk1.1.7B\bin\java -classpath
> C:\jdk1.1.7B\lib\classes.zip;C:\mm\mm.mysql.jdbc.1.1f\mysql.jar;. testfile
> 
> -this is what follows:
> 
> Driver registered
> java.sql.SQLException: Cannot connect to MySQL server on anton:3306. Is
> there are MySQL server running on the machine/port you are trying to connect to?
>         at org.gjt.mm.mysql.Connection.<init><Connection.java:237>
>         at org.gjt.mm.mysql.Driver.connect<Driver.java:126>
>         at java.sql.DriverManager.getConnection<Compiled code>
>         at java.sql.DriverManager.getConnection<DriverManager.java:126>
>         at testfile.main(testfile.java:21)
> 
> - code for testfile.java:
> 
> import java.sql.*;
> 
> public class testfile {
>    public static void main(String args[]){
>       String url = "jdbc:mysql://dbserver:3306/javatest";
>       String user = "myname";
>       String password = "mypassword";
> 
>       String myDriver =  "org.gjt.mm.mysql.Driver";
> 
>       try {
>          Class.forName(myDriver);
>          System.out.println("Driver registered");
>       }
>       catch (Exception e){
>          System.out.println("could not register driver");
>          return;
>       }
>       try{
> 
>          Connection con = DriverManager.getConnection(url,user,password);
>          System.out.println("we have connection"); //this never reached...
>          con.close();
>       }
>       catch (SQLException ex ){
>          ex.printStackTrace();
>       }
>    }
> }
> 
> kind regards Paal Are
> 
> _______________________________________________________________
> Paal Are Solberg,

Hi Paal Are

Is mysqld really running on "dbserver"?
Can you reach "dbserver" from your NT machine?
(e.g. can you ping to "dbserver"?)
Can you telnet to port 3306 on "dbserver" from the NT machine?
Can you connect with mysql commandline client to the "dbserver" from the NT machine?

Your code seems to be OK, only "Class.forName(myDriver);" should be changed to
"Class.forName(myDriver).newInstance();", because this prevents a known bug with some VMs
(but not the one you see here).

Tschau
Christian

PS: Sorry for the late answer, I was on vacation.

Thread
cannot connect to mysqlPaal Are Solberg15 Jul
  • Re: cannot connect to mysqlChristian Mack21 Jul