I am able to deploy the application on my local system.... connecting to the same remote database... however when I deploy the same war file on the ubuntu server I get the following exception
javax.servlet.ServletException: Could not connect to wikipedia database...
org.wikipedia.miner.service.WikipediaMinerServlet.init(WikipediaMinerServlet.java:81)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:616)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject.java:537)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:115)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Thread.java:636)
I have even placed the mysql connector jar under tomcat6 lib direcotry.... Please help
Are the two MySQL servers configured identically? Both allow access via TCP sockets and/or local Unix-domain sockets?
"Could not connect" suggests that JDBC can't even reach the server to try and log in. If you're connecting via TCP, check if there's a firewall rule in place preventing local connections (localhost:* -> localhost:3306 is denied). For local sockets, check that the user Tomcat's running under has access to both the socket file, AND the directory it resides in (should be /var/run/mysqld/mysqld.sock).
Related
I was trying to establish connection to mysql database, using Jenkins pipeline and when do that I get the following error:
com.mysql.cj.exceptions.UnableToConnectException: CLIENT_PLUGIN_AUTH is required
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
MySQL db version is 5.1.73
For the same database when I use mysql-connector-java-5.1.39-bin.jar in a Java program I was able to establish connection. But for the version below , higher or the same mysql-connectors I was not able to connect using Jenkins pipeline.
I searched internet and was not able to find a solution. Version compatibility was always mentioned as problem in some posts for this error trace in Java.
Plugins used in Jenkins are database & database-mysql
Here's my pipeline script
import groovy.sql.Sql
node{
Class.forName("com.mysql.jdbc.Driver")
dbConnection = Sql.newInstance("jdbc:mysql://localhost:3306/test", "username", "password","com.mysql.jdbc.Driver")
}
At the moment I am trying to follow this documentation in order to connect to my Second Generation Cloud SQL database. However, my application fails on startup since it cannot connect to it ..
As been told by the documentation, I have added both service accounts
my-project#appspot.gserviceaccount.com
1234-compute#developer.gserviceaccount.com
as Editor under IAM.
I am using the IPv4 of the Cloud SQL instance to connect. Here the connection string:
jdbc:mysql://w.x.y.z:3306/app_db?useSSL=false
but in the Stackdriver Logging view I see:
[main] ERROR com.mz.server.BootstrappingServerConfig - Error trying to migrate SQL scripts ..
org.flywaydb.core.api.FlywayException: Unable to obtain Jdbc connection from DataSource
at org.flywaydb.core.internal.util.jdbc.JdbcUtils.openConnection(JdbcUtils.java:56)
at org.flywaydb.core.Flyway.execute(Flyway.java:1385)
at org.flywaydb.core.Flyway.migrate(Flyway.java:1006)
...
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
...
Caused by: java.net.ConnectException: Connection timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
...
Both instances are in the same region: us-central1-b for the compute instances and us-central1 for the SQL instances.
My app.yaml file:
runtime: java
vm: true
runtime_config:
jdk: openjdk8
server: jetty9
env_variables:
'ALPN_ENABLE': 'true' # OPTIONAL
beta_settings:
cloud_sql_instances: mz-test:us-central1:mz-test-cloudsql
health_check:
enable_health_check: false
I am not sure what's wrong here. Am I actually allowed to use the local IPv4 address of the SQL instance?
The documentation actually says
"In your application code, connect to the instance by opening a socket with the following name: /cloudsql/[INSTANCE_CONNECTION_NAME}"
But I am not sure what that would mean for the connection string.
I am also missing the information about what username/password is required or do I not need one here?
Why am I not able to connect?
For Java applications running on App Engine Flexible Environment applications use the following library: https://github.com/GoogleCloudPlatform/cloud-sql-mysql-socket-factory
I have a xampp server running on a AWS-EC2 Ubuntu instance, and I have a database there that is called "androiddb". I can access the database by writing in a navigator http://public_ip/phpmyadmin and entering with "root" user and no password.
In another side I have a Java application that needs to connect with that database, and I have the following line in my code to do it:
con = DriverManager.getConnection("jdbc:mysql://public_ip/androiddb",
"root", "");
When I run my application, I get the following error:
Error: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused
STACKTRACE:
java.net.SocketException: java.net.ConnectException: Connection refused
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:284)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2569)
at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at Presentacion.Presentacion$2.mouseClicked(Presentacion.java:125)
at java.awt.Component.processMouseEvent(Component.java:6519)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6281)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4872)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4501)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:747)
at java.awt.EventQueue.access$300(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:706)
at java.awt.EventQueue$3.run(EventQueue.java:704)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:720)
at java.awt.EventQueue$4.run(EventQueue.java:718)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:717)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
** END NESTED EXCEPTION **
Last packet sent to the server was 19 ms ago.
Also I looked for the port where mysql was running and I used the code:
SHOW VARIABLES
WHERE Variable_name IN (
'hostname',
'port')
I write this piece of code in phpmyadmin in the SQL section, and I get the following output:
Variable_name Value
hostname ip-172-31-23-224
port 0
I don't know what does port 0 mean, it should be 3306 (default mysql port)...
Anyways, I don't know if I'm doing something wrong with the xampp configuration or if it's problem of AWS or anything else.
Could someone help me with this? Thank you very much.
You should ensure your security groups for AWS are open on the 3306 port (or whatever you configure) so they can access the database.
You could trouble shoot by trying to SSH into the machine, can you connect locally? If yes, then look at your security groups and open the port. If you can't connect locally than the database is down and you need to diagnose and configure the DB correctly.
But a connection refused is more than likely a port not being open in the security group.
Just to add what solved his issue:
He checked his security groups and opened the correct ports
Checked locally to see that mySQL wasn't listening on any port
netstat -tlnp to check to see SQL running locally
Checked the my.ini file to see that mysql was configured to listen on a port
Found it wasn't and reconfigured it to listen
It may help some working with phpMyAdmin and AWS and Amazon's relational database service (RDS) to know that phpMyAdmin will not work unless the RDS endpoint is edited into the "localhost" or "127.0.0.1" location in the config.inc.php file. (It is a necessary but not sufficient fix -- you may need to do other things...)
Generalizing a bit, if you are using foo and it has a config file, and you are looking to connect to a database instantiated under RDS, you'll need that endpoint as host entry.
I cannot figure out how to access a MySQL database while running in Jenkins CloudBees. I have tried following the Dev#Cloud MySQL, but there are a lot of warnings in the console output and I have to deal with localhost access vs. sockets, which is pretty tricky to debug without a command line.
Is there a way to use the CloudBees MySQL hosting? When I try and use the cloudbees JDBC driver, I get ClassNotFound error messages.
Update: The answer below clarified that I cannot use the CloudBees driver, so I am now using the regular MySQL connector through the c3p0 connection pool. Based on comments below, I have limited the number of connections in the pool to 10.
The exact same configuration and Maven command line works when I run it from my development computer, connecting to the Cloudbees Mysql instance.
Unfortunately, I get this error when trying to connect:
Caused by: com.googlecode.flyway.core.exception.FlywayException: Unable to obtain Jdbc connection from DataSource
at com.googlecode.flyway.core.util.jdbc.JdbcUtils.openConnection(JdbcUtils.java:56)
at com.googlecode.flyway.core.Flyway.execute(Flyway.java:864)
at com.googlecode.flyway.core.Flyway.migrate(Flyway.java:591)
at com.assuredlabor.db.DatabaseMigrator.migrate(DatabaseMigrator.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1414)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1375)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 62 more
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
at com.googlecode.flyway.core.util.jdbc.JdbcUtils.openConnection(JdbcUtils.java:50)
... 72 more
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
... 74 more
Any ideas would be appreciated.
You can't use CloudBees JDBC driver from outside the RUN#Cloud container, but you can use a standard MySQL JDBC driver with your RUN database using the host name and port that you can find on RUN#Cloud web console for your DB resource.
I was using MS-Access and Tomcat 6.0 previously for my application testing and it was working fine.
Now I want to use mySQL database through Apache Tomcat 6.0. I have WAMP server installed on my computer and I want to connect to the mySQL server. I have succesfully created a database on it. I have put mysql-connector-java-5.1.9, mysql-5.0.85-win32 , mySQL driver in lib of tomcat 6.0 as well as that of my application to ensure it is in classpath. I have following code in my jsp.
Driver d = (Driver)Class.forName("com.mysql.jdbc.Driver").newInstance();
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql:3306///tmp/mysql.sock",
"admin", "admin");
[wampmysqld]
port = 3306
socket = /tmp/mysql.sock
I am getting error as
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:128)
at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:66)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.apache.jsp.insert_jsp._jspService(insert_jsp.java:78)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:574)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1527)
at java.lang.Thread.run(Unknown Source)
What changes do I have to make in my web.xml file/server manager?
Did you download the MySQL JDBC driver from
http://dev.mysql.com/doc/refman/5.0/en/connector-j.html
Is that jar file in your classpath? The error you are showing indicates that the MySQL JDBC Driver IS NOT in your classpath.
I have put mysql-connector-java-5.1.9 , mysql-5.0.85-win32 , MS sql driver in lib of tomcat 6.0 as wel as that of my application to ensure it is in classpath.
First, what are the actual files?
mysql-connector-java-5.1.9 - I'm assuming this is the JDBC driver - the actual file should be mysql-connector-java-5.1.9-bin.jar
mysql-5.0.85-win32 - what is this? The MySql installer? If so, you don't need this.
MS sql driver - I thought you wanted MySQL?
Second - "in lib of tomcat 6.0 as wel as that of my application to ensure it is in classpath." - Don't do this... it needs to be in one or the other - not both.
Third - "jdbc:mysql:3306///tmp/mysql.sock" - isn't a correct JDBC connection URL - it's something like - jdbc:mysql://localhost:3306/databaseName
You should be able to copy mysql-connector-java-5.1.9-bin.jar into either your Tomcat lib directory or packaged in your WAR's lib directory, and then use the correct JDBC connection string to connect to this database in your code.
There's a page on how to set up many databases (including MySQL) as a JNDI DataSource in Tomcat 6.0 - this is above and beyond what you're trying to do here, but the initial steps are the same, and it provides some example configurations.
You have to put the mysql driver JAR file in apache-tomcat/common/lib/ directory
You can download it from http://dev.mysql.com/downloads/connector/j/5.1.html
You need to put the mysql-connector.jar there
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/project","admin", "admin");
Note there was : missing before local host.