• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Empty connection Mysql

 
Isaac Ferguson
Ranch Hand
Posts: 1041
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I try to connect with a DDBB which is remote, I am using the next code:

In the DAO file I have this code:



Then an specific file for the DB:




In the Tomcat Log I get this message:



I looks that the driver is invalid in my case

Any idea?
 
Dave Tolls
Ranch Hand
Posts: 2112
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Print out the full stack trace.
Without that you won't know what the exception was.
I can guess (possibly a ClassNotFoundException), but it would be just that, a guess.
 
Isaac Ferguson
Ranch Hand
Posts: 1041
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right here it is:



It says that the connection is null it cant get anything from it

When I debug it crashes here:

 
Isaac Ferguson
Ranch Hand
Posts: 1041
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I went a little bit further, now the error I get when debbuging is :



Im using this driver



And my jar is:



Any idea?
 
Isaac Ferguson
Ranch Hand
Posts: 1041
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have changed the parameter for try to connecting in local instead to a remote DB.

Thi sis error i get when debbuging.



An this is the code;



The message in the console is:





It just get null when tryin gto create a connection

Any idea?
 
Dave Tolls
Ranch Hand
Posts: 2112
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's an ancient version of the connector.
Not sure if there was any change in the URL between that and the current version 5.

Why aren't you simply doing ex.printStackTrace() in that catch block? It would be simpler.
That gives you the full information, including the exception name.

That exception you are showing is caused by you returning null from your getConnection() call. You need to handle a failure to connect, even if it's simply to exit with an error.
 
Isaac Ferguson
Ranch Hand
Posts: 1041
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed to System.out.println("Database.getConnection() Error -->" );
ex.printStackTrace();


I get the same error.

Which driver/ jar should I use?

Regards
 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be using the latest driver which can be downloaded at http://dev.mysql.com/downloads/connector/j/

Also which java version are you using? Java 6 or later utilizes JDBC4 hence the line

is optional, but for backward compatibility you may want to keep it in.
 
Isaac Ferguson
Ranch Hand
Posts: 1041
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that website I found an installer but not the jar itself

I already installed that in my local, bu tI need the jar
 
Tim Holloway
Saloon Keeper
Posts: 18367
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Run the installer.

I have no idea where it might have put the jar, though. Send the puppy looking for "mysql-connector" or something like that.

You could always download the OS-independent archive and pull the jar out of that file, though.
 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the platform-independent (zip) version so that you can find the jar directly in the zip file.
 
Dave Tolls
Ranch Hand
Posts: 2112
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isaac Ferguson wrote:I changed to System.out.println("Database.getConnection() Error -->" );
ex.printStackTrace();


I get the same error.


Regards


Well, you would get the same error, since you return null, but you should also get a stack trace earlier which explains the root cause of the problem.
 
Isaac Ferguson
Ranch Hand
Posts: 1041
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the complete error in console:




At the catalina file of Tomcat the is not error there

Any idea?
 
Dave Tolls
Ranch Hand
Posts: 2112
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.sql.SQLException: Communication link failure: java.io.IOException

It can't talk to the db for some reason.

(Also you should edit that lot as only the exception is needed. The rest is causing a scrolling issue on the page.)
 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to get the database connection to work outside of Tomcat so that you know it's not the java code causing the problem.

Once you got that then go back to Tomcat.

From what I see, I suspect it's Tomcat configuration.
 
Isaac Ferguson
Ranch Hand
Posts: 1041
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I sorted it out. I was because I was not using the rigth credentials, for conection to the database (the host was wrong).

Thanks
 
Isaac Ferguson
Ranch Hand
Posts: 1041
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my local it works fine like this:





but it fails in remote. It launches this error:




The credentials are right, and I am using the same driver I only changed this



for this:




Any idea?

Regards,
Isaac
 
Dave Tolls
Ranch Hand
Posts: 2112
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you changed anything else?
Is it running on the same machine?
From the same project?
All that has changed is that one line of code?
 
Isaac Ferguson
Ranch Hand
Posts: 1041
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I didnt change anything else, now Im debugging and the error I get is this:



I have found the point in which the error happens:



At this exact line:



Debbuging it gives me this error:





It looks like a driver is not been assigned to the variable:




Any idea?
 
Dave Tolls
Ranch Hand
Posts: 2112
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code hasn't been compiled with all debugging information, which is what the -g flag is for.
So you have no variable name info available.

What version of ConnectorJ are you using, and what version of MySQL is it talking to?
 
Isaac Ferguson
Ranch Hand
Posts: 1041
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where could I add the -g for see the variable info?

Im using this: com.mysql.jdbc_5.1.5.jar

DB client version: libmysql - 5.1.73

The app is in my local machine and the DB is hosted at HostGator server

Any idea?
 
Dave Tolls
Ranch Hand
Posts: 2112
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you connect with a simple app?
That is, no Tomcat or anything, just a standalone app.

Failing that, can you connect with something like SQL Developer?
 
Isaac Ferguson
Ranch Hand
Posts: 1041
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I dont get it



Do you mean an app which run without a server?



Do you mean changing the DB?
 
Dave Tolls
Ranch Hand
Posts: 2112
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isaac Ferguson wrote:Sorry I dont get it



Do you mean an app which run without a server?


Yes.
A nice simple one that gets a connection and maybe does a simple query.

Isaac Ferguson wrote:


Do you mean changing the DB?


No, SQL Developer.
It's a tool for working with databases.
 
Isaac Ferguson
Ranch Hand
Posts: 1041
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried both things:

It launches de same error:

This is the code:

try {
Class.forName("com.mysql.jdbc.Driver");

// Connection con = DriverManager.getConnection("jdbc:mysql://domain-name:2082/dbNAme","name","pass");

Connection con = DriverManager.getConnection("jdbc:mysql://IP:2082/dbNAme","name","pass");


return con;
}
catch(Exception ex) {
System.out.println("Database.getConnection() Error -->" );
ex.printStackTrace();
return null;
}
}

Any more idea?
 
Dave Tolls
Ranch Hand
Posts: 2112
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, SQL Developer failed to connect?

And the full exception (and stack trace) you get from the standalone test program?
 
Isaac Ferguson
Ranch Hand
Posts: 1041
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used Mysql interface when testing connection and it fails.

The erroe at the console is:



Any idea?
 
Dave Tolls
Ranch Hand
Posts: 2112
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've a connection problem then.
Firewall maybe.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic