I have a webapp that is running properly in Tomcat without the database.
If I add the following to tomcat context.xml it seems to kill the whole server, I get a blank page and connection refused for my app and the tomcat manager app:
<Context docBase="${catalina.base}/webapps/ROOT.war">
<Parameter name="application.properties" value="/home/users/tomcat/application.properties"/>
</Context>
There is an application.properties file in /home/users/tomcat/ which is the same user that runs tomcat. So how come this line is bringing my server down?
MySQL 5.5 is running and the properties file I used is:
spring.datasource.url=jdbc:mysql://localhost:3306/springboot
spring.datasource.username=automation
spring.datasource.password=xxxxxxxxxxxx
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#comment out below line to create schema on new database
spring.jpa.hibernate.ddl-auto=update
How do I troubleshoot the database connectivity?
I know mysql is configured for port 3306 and it will let me login with the details in that file, if I use SSH.
Related
I am trying to connect to MySQL server at remote machine using spring-boot application.properties but it is failing with error o.s.b.a.orm.jpa.DatabaseLookup: Unable to determine jdbc url from datasource.
My database URL is in the correct format. Remote Server requires ssh connection and I have connected it successfully using MySQL Workbench. For connection via spring-boot app, I checked solutions and implemented JSCH solution as explained in post:
Spring Boot SSH Mysql? but still no success.
Remote Server SSH port is 202 instead of default 22. Any help on how to connect DB?
Please refer information mention here -
here
or
stackoverflow page
I built the MySQL connector and the database details into the app and it still wont connect to MySQL when running in Tomcat. My app is entirely open source and all source code is on the web at: https://github.com/clickcell/AutomationStatisticsPortal
The application.class
The gradle build file
The application.properties file, different from my repository, is:
spring.datasource.url=jdbc:mysql://localhost/springboot
spring.datasource.username=newuser
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
I have tried setting up the MySQL 5.5 server to match application.properties
Every time the symptom is as follows:
Web app running but there is no database connection, no data being displayed.
I use Tomcat8 and MySQL 5.5. I have enabled the query log and monitor it using tail -f when I run queries direct to the server they show up in the log but when I reboot my app in the tomcat manager, nothing shows up in that log.
In the tomcat log I get the following:
21-Dec-2016 10:19:16.693 INFO [http-nio-8080-exec-6] org.apache.catalina.core.StandardContext.reload Reloading Context with name [/AutomationStatisticsPortal] has started
21-Dec-2016 10:19:17.339 WARNING [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [AutomationStatisticsPortal] registered the JDBC driver [org.h2.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
21-Dec-2016 10:19:19.026 INFO [http-nio-8080-exec-6] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
21-Dec-2016 10:19:26.839 INFO [http-nio-8080-exec-6] org.apache.catalina.core.StandardContext.reload Reloading Context with name [/AutomationStatisticsPortal] is completed
It looks like it's registering the wrong kind of database driver, but I do not know why given my configuration.
The log you've shown is produced when H2 is used.
I cloned your repository and tested locally, it works when I update the src/main/resources/application.properties with MySQL parameters.
You should remove the other one in root, it's ambiguous.
You could also replace your application.properties file in src/main/resources with this application.yml file:
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://localhost/springboot
username: newuser
password: password
jpa:
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
database: MYSQL
show-sql: true
In this case, add the Hikary dependency, or use another datasource type.
I am working on a remote Redhat system over SSH. Tomcat 7 and MySQL 5.5 server are both installed and appear to be running correctly.
I can connect to MySQL from a local install of Workbench over SSH tunneling using localhost and a defined MySQL user. I can run queries and navigate tables without incident.
When I try to connect to the same MySQL Server with a Tomcat application running in the same environment using the MySQL defined user (same credentials) that Workbench is connecting with successfully, it fails.
At this point I don't know the exact error message that gets generated (I am not an admin) so any guidance here is appreciated.
My question is why can I connect with Workbench (which is effectively connecting locally), but not with my Tomcat application, which actually is local to the server?
Might it be a permissions issue with the context Tomcat is running under?
References:
Connection string example (credentials have been altered):
jdbc:mysql://localhost/mysql_database_name?user=ApplicationUsername&password=ApplicationPassword"
Furthermore, I have verified that
mysql-connector-java-5.1.27-bin.jar
is in the WEB-INF folder, and:
Class.forName("com.mysql.jdbc.Driver");
resolves.
This web application works in both dev and test on another server connecting using respective credentials.
Be sure the port number of mysql server exists in connection string. Normally if port is not specified, default value would be used as 3306. Maybe your mysql runs on different port?
jdbc:mysql://[host][,failoverhost...][:port]/[database] ยป
[?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...
If the host name is not specified, it defaults to 127.0.0.1. If the port is not specified, it defaults to 3306, the default port number for MySQL servers.
I have created a java application which connects to a mysql database using the JDBC driver. I have the mysql server running on the same machine as my java application.
When I connect to the database on localhost the application is working fine. My system in connected to other systems via LAN. Now i want to run my application on these systems connecting to the database on the mysql server i have on my system.
What changes do i need to make in my mysql workbench or the java application to deploy this. I have mysql 6.1 workbench installed.
I am getting the following error:
run: Communications link failure
Last packet sent to the server was 0 ms ago. Exception in thread
"AWT-EventQueue-0" java.lang.NullPointerException
at help.helpdesk.Ready(helpdesk.java:97)
at help.helpdesk.<init>(helpdesk.java:89)
at help.helpdesk$6.run(helpdesk.java:428)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) BUILD
SUCCESSFUL (total time: 22 seconds)
when I try to connect to the database on my local server by using the ip address of my system.
If you set bind-address = 0.0.0.0 in /etc/my.cnf, MySQL will be available across all interfaces both locally and over the network.
You need to do following changes
1.Edit the my.cnf
mysql/my.cnf
change the local ip
bind-address = 192.168.1.2("your system ip")
2.restart the mysql server
and if you want connect to your database remotely than this link will helpful for you
I created my scaled application on Openshift server with following command:
rhc app create MyApp jbossews-2.0 -s
Then add Mysql:
rhc cartridge add mysql-5.5 -a MyApp
My application using Struts2, Spring & Hibernate. I configured the datasource as follow:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/MysqlDS"/>
</bean>
The JNDI "MysqlDS" is defined in .openshift\config\context.xml with the connection url:
url="jdbc:mysql://5344d4de4382ec43c9000090-myapp.rhcloud.com:37941/mydb"
The problem is my scale app can not establish the connection to Mysql with an error:
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect
3 times. Giving up.)
I'm sure the username & password to access the database is correct. It seem MySQL on Openshift server doesn't open its port. When I tried to use an external database on freemysqlhosting.net (with open host & port) the application run well. But I just want to use MySQL db on Openshift. Anyone who have experience on this please give me some suggestion. Thanks
Make sure that you restarted your application after adding the mysql cartridge, sometimes the environment variables don't show up correctly until you restart. Also try to ssh to your gear and see if you can use the "mysql" command to connect to your mysql database directly.
If you left the .openshift/config/context.xml unchanged, the JNDI name fore the MySQL datasource is actually jdbc/MySQLDS and not jdbc/MysqlDS.
This was changed some time ago.
The documentation here http://openshift.github.io/documentation/oo_cartridge_guide.html#tomcat-cartridge-integrations is unfortunately not correct.