Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Eclipse does not connect to MySQL

 
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I work in full opensource, os: Debian 8.8, Eclipse oxygen, Tomcat 8.0, Mysql 5.7.20, MySql Workbench 6.2.
I develop a java EE application, with the base Mysql and tomcat, I realized that the connection with mysql does not work.
I also develop in PHP5 / CCS3 == here everything works well I have access to my tables! and of course MySql Workbench works very well!
I'm using the latest connector: mysql-connector-java-5.1.45-bin.jar in the Eclipse web-inf lib.
When I try to set my database / ping answers failed!
Here are my settings
1 / database: javaee
2 / URL: jdbc: mysql: // localhost: 3306 / javaee
3 / user and password well filled.
4 / (optional) in java EE my tables etc ....

it does not work, in the beginning I thought it was my programs that do not work but no, the connection is refused!
eclipse error message:


Regards
Philippe
 
Sheriff
Posts: 7108
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two thoughts:

* can you manually connect with user root and password?

* can you connect with a non-root user and password?

("Manually connect": using the command line or some application outside of your Java program.)
 
Saloon Keeper
Posts: 22289
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is incorrrect to say "Eclipse does not connect". Eclipse has no built-in database capabilities. There are plugins for Eclipse that can and do connect, but those plugins have to be installed independently and they are primarily intended to allow Eclipse to be used as a "control panel" for database operations. That is a completely separate thing from an application program that's developed under Eclipse. And remember, Eclipse is just the design tool. The application will not have Eclipse or any of the Eclipse components available when it gets deployed in a production environment.

As far as the application itself goes, a well-written J2EE webapp should not be using DriverManager.getConnection(). That is an extremely inefficient way to connect to a database in a multi-user, multi-threaded environment like a webapp server. Instead, use a database connection pool. The connection pool is set up as part of the Tomcat configuration.

As far as the connection configuration itself, the most common causes for a connection attempt to fail are:

1. Invalid connection URL - usually bad URL syntax or invalid host, database or port ID. MySQL is most likely to use port 3306 or 3305.
2. Firewall issues - Note that on many machines, even localhost connections are passed through the local OS firewall. You must ensure that the client machine permits an outbound connection for port 3306 to the server machine and that the server machine will accept incoming requests for port 3306 from the client machine.
3. Resource availability - the server is down or is overloaded and cannot honor the connection request. On a related note, the client machine can run out of TCP/IP connections (which is one reason why Connection pools are recommended).
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
according to my research it is necessary to create a "pool" for MySql and to create a file server.xm
l to inform in the web-inf, here is my file server.xml, there are many errors but it is a beginning:




if you have ideas they will be welcome!

Regards
Philippe
 
Tim Holloway
Saloon Keeper
Posts: 22289
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not define the pool in server.xml for most application systems. The server.xml file is Tomcat's master configuration file. Usually you will define a connection pool for just one webapp (although you can share a pool between webapps if that benefits you).

To define a configuration pool at the webapp level you need to understand that there are two deployment descriptor files for each webapp (Tomcat will synthesize either or both of these files if they do not exist, but if so, the deployment descriptor will be made up of default values).

The server-independent deployment descriptor is well-known. It's the WEB-INF/web.xml file in the webapp's WAR.

The server-dependent deployment descriptor depends on what brand of server you are using. In the case of Tomcat, it's the Context file.

The Context file can be located in several places (if there's more than one, there are precedence rules on which one gets used). If no file exists, Tomcat  makes its equivalent using defaults. For example, the default webapp URL context for a WAR located in TOMCAT_HOME/webapps/mywebapp would be "/mywebapp". For non-default parameters (such as Connection Pool definitions), you'll need a Context XML file as described in the Tomcat documentation. You can create this file as META-INF/context.xml in the WAR or in TOMCAT_HOME/conf/Catalina/localhost/mywebapp.xml (for example). If you define the context in conf/Catalina/localhost, the URL context path will be the same as the file name (minus the ".xml" extension).

Here's a sample context XML:



This Context defines a PostgreSQL datasource, but MySQL is configured much the same. Note also that my docBase is a build directory within my Eclipse workspace (This project is built by Maven, so the build is done to the "target" directory).
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

thank you Tim for this information.
indeed the server.xml is dedicated tomcat, I made a mistake!
I chose among your advice to make an independent server,
I just have to make an implementation of the web.xml and describe the tag "context"
but that being said I miss information you need to know from a la maven configuration,
there are some errors in my description, here is the code:



my database is javaee
the name of my project is "boticiel"
i work in the local host
should I fill in the password by the true or leave "secret"?

regards
philippe
 
Tim Holloway
Saloon Keeper
Posts: 22289
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your URL is incorrect. The "javaee.localhost" part is supposed to be the domain name or IP address of the server machine. So it might be "localhost", "localhost.localdomain", "127.0.0.1", "database.javaranch.com" or something like that. Most JDBC drivers expect that if you're naming a specific database, that the database name will be the first segment of the URL past the domain name part. For example, "database.mousetech.com/mydatabase". However that part is up to the driver designer and sometimes they use other notations.

Regardless, the database name and the machine domain name are 2 different types of names and would not be combined, since the OS-level domain name resolver could not make sense of it and therefore the driver could not figure out what the actual network address of the database machine was.

The concept of "project name" is meaningless to MySQL. Possibly the closest approximation would be a schema name.

And yes, you MUST provide a valid database userid and password as part of the pool definition. MySQL is extremely secure and will not allow network connections from invalid userid/password combinations. Or, in fact, even from valid userid/password combinations unless there's a MySQL security profile that allows that specific client host to use those credentials.

Incidentally, the "path=" attribute of a Context element is usually ignored. When the context file has been deployed to TOMCAT_HOME/conf/Catalina/localhost/xyz.xml, the URL context path assigned will be "/xyz", not "/root/eclipse-workspace/boticiel".
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
In a french forum a person tested his code under Debian 8.6 with an old MySql server,
he met the same problem as me, he can not get to MySQL in JEE
so he has to change the BIND line of the configuration file MySql,
and it works well, he also removed the "try catch" when loading the JDBC driver.
I change application server and switch to Tomcat 9.2, I try everything!
I checked my Bind in the Mysql server configuration file, it points to 127.0.0.1 is localhost.
I still can not connect! here is my method of loading the driver jdbc

from what you say about your test is that there is no XML parameterization.
I stopped my APACHE2 server in case of conflict!
do you have like me the same SQL imports as me or it is missing.

In your code you remove the (try catch) exception to load the MySQL driver.
I think the error is in the declaration of the JDBC driver because in PHP 5.x I was doing PDO.


Greetings
philippe

PS: you are many to develop in JEE under Microsoft Windows, I no longer work under MS Windows with virus problems or other instabilities.
this is done to make the staff laugh that I find too serious because I never jokes .. to say that to work under MS windows because
you with actions at bill gates with are famous slogant "buy prodiuct on the screen"!
 
Tim Holloway
Saloon Keeper
Posts: 22289
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do not present me with code like this:


If you live on the same continent as I do and wish to avoid serious bruising.

"Eating" exceptions is a sure-fire way to enrage me. ALWAY handle, report, or rethrow exceptions. Don't make them silently disappear!

If you use a database connection pool - as I have recommended - the logic you just illustrated will not obtain a pool connection.

To get a connection from a pool, this is the logic that you must use:


To use the Connection pool, you also must copy the MySQL driver JAR into TOMCAT_HOME/lib. Tomcat cannot look inside your WAR for drivers used in pools.
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi  Tim Holloway,
I tried my project on another computer, same thing, in full 64 bits, but with "MariaDB" as database and Debian 9.1,
I met the same problem which it is necessary to create a pool.



so far I understand more or less encoding, but the rest of your code.
I do not know or place it in my code, should I do a class?


here are the methods to declare my loaddatabase in the bean class :


i tryed to delete

But the IDE return error !

I do not understand your message

Incidentally, the "path=" attribute of a Context element is usually ignored. When the context file has been deployed to TOMCAT_HOME/conf/Catalina/localhost/xyz.xml, the URL context path assigned will be "/xyz", not "/root/eclipse-workspace/boticiel".



I do not have a domain name in my networks
 
Tim Holloway
Saloon Keeper
Posts: 22289
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You deleted the catch, but not its matching "try".

What I meant, however, was that if you code a try/catch, at a minimum do this:


Otherwise no one will be able to tell from the outputs whether the exception happened or what its details were. Which makes it VERY hard to debug.

You may "not have" a domain name, but when you coded a "hostname" in the form of "javaee.localhost", the operating system assumed that you were indicating a fully-qualified domain name (FQDN), where the hostname was "javaee" and the domain name was "localhost". The dot separates the hostname from the domain name - a dot is not a valid character within a hostname ID.

Under Linux, even if you don't define any other host or domain names, the OS installer will always create a local FQDN of localhost.localdomain and its IP address will always be 127.0.0.1. If you specify an unqualified hostname (without a domain), then the OS name resolver will assume that the domain for that hostname is the domain of the local machine.
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
i don"t found the name of domaine for my project.
i have tryed with

but eclipse return error !

how can i do to find a good local domaine ?
 
Tim Holloway
Saloon Keeper
Posts: 22289
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You really, really need to study basic networking concepts. This goes far beyond Java. There are too many cases where to explain things I have to explain the things that explain things.

The "path=" attribute on a Tomcat Context element has nothing to do with networking or with domains. It defines the context path part of a URL directed to that Tomcat server instance.

The context path is the part of the URL that follows the server/port information and precedes the application-specific data part of the URL. In Tomcat, this path indicates which of possibly many webapps hosted by that Tomcat server instance the URL request should be routed to for processing.

So if I have 2 webapps on my local system and we'll call them "appA" and "appB", I can define context paths such as "accounting" and "email" such that http://localhost:8080/accounting/ URLs get sent to appA, and http://localhost:8080/email URLs get sent to appB.

However, as I said earlier, the "path=" attribute is completely ignored when you deploy a context XML file to TOMCAT_HOME/conf/Catalina/localhost, because Tomcat will use the name of the context.xml file as the context pathname.
 
If you live in a cold climate and on the grid, incandescent light can use less energy than LED. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic