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.
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")
}
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.
when I try to run the MySQL Migration Toolkit GUI in Windows, I get an error that states Java is not installed. Java is installed, but Migration Toolkit doesn't recognize it. Does anybody know how to solve this problem?
Well in order for this to work the solution is really easy.
Go to folder you have installed MySQL Migration Toolkit.
Make a shortcut e.g. to your desktop of the executable file MySQLMigrationTool.exe
Then right click on the shortcut you just created and on the target modify it like this
"C:\Program Files (x86)\MySQL\MySQL Migration Toolkit 1.0\MySQLMigrationTool.exe" -verbose -jvm **The Path to your 32bit jvm.dll**
e.g for my installation with jre1.8.0_45 was
"C:\Program Files (x86)\MySQL\MySQL Migration Toolkit 1.0\MySQLMigrationTool.exe" -verbose -jvm ***"C:\Program Files (x86)\Java\jre1.8.0_45\bin\client\jvm.dll"***
You should really try the new Migration Wizard that comes with recent MySQL Workbench versions. The MySQL Migration Toolkit has been phased out several years ago and is not under active development.
For a tutorial on the Migration Wizard take a look at How-To: Guide to Database Migration from Microsoft SQL Server using MySQL Workbench.
Anyway, if there's still somebody struggling with the MySQL Migration Toolkit and jre 1.8 I would suggest to stop bothering because after fixing the boot by setting the jvm.dll it fails performing the Reverse Engeneering step with this message:
The schema could not be reverse engineered (error: 0).
ReverseEngineeringAccess.reverseEngineer :sun.jdbc.odbc.JdbcOdbcDriver
Details:
java.net.URLClassLoader.findClass(Unknown Source)
java.lang.ClassLoader.loadClass(Unknown Source)
sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
java.lang.ClassLoader.loadClass(Unknown Source)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Unknown Source)
com.mysql.grt.modules.ReverseEngineeringGeneric.establishConnection(ReverseEngineeringGeneric.java:84)
com.mysql.grt.modules.ReverseEngineeringAccess.reverseEngineer(ReverseEngineeringAccess.java:92)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.mysql.grt.Grt.callModuleFunction(Unknown Source)
I got the tool running and migrated most of the tables but is not happy with the result because many table creation failed. Still it is useful since I got the script so that I can edit it later. I used these versions
Migration Toolkit 1.0.25
IBM JRE 5.0 (I had this in system) - Had to set the JVM as mentioned by John.
Use Oracle JDBC driver for your database(12c ojdbc8) but it must be renamed to ojdbc14.jar and use.
Delete mysql-connector-java-3.1... files(3 files) from MySQL Migration Toolkit 1.0\java\lib and place mysql-connector-java-5.1.44.jar
Run the tool.
I used mysql_native_password for the MySQL user :-
ALTER USER 'mysqluser'#'%' IDENTIFIED WITH mysql_native_password BY 'pass';
I have been put in charge of migrating the data out of an MS SQL Server 2008 database into MySQL. I have installed Microsoft SQL Server Management Studio, have started the SQL Server and SQL Server Browser services, have enabled the TCP/IP and Named Pipes protocols for the sql database via the SQL Server Configuration Manager, and created a user with access via SQL Authentication instead of Windows Authentication. I am trying to get the data out using MySQL Migration Tool. When I try to connect to the server I get the following error:
Connecting to source database and retrieve schemata names.
Initializing JDBC driver ... Driver class MS SQL JDBC Driver Opening
connection ... Connection
jdbc:jtds:sqlserver://ukoff032/sqlexpress:1433/DbMain;user=remoteAccess;password=password;charset=utf-8;domain=
The list of schema names could not be retrieved (error: 0).
ReverseEngineeringMssql.getSchemata :Network error IOException:
Connection refused: connect Details:
net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:372)
net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java:50)
net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:178)
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
com.mysql.grt.modules.ReverseEngineeringGeneric.establishConnection(ReverseEngineeringGeneric.java:141)
com.mysql.grt.modules.ReverseEngineeringMssql.getSchemata(ReverseEngineeringMssql.java:99)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.mysql.grt.Grt.callModuleFunction(Unknown Source)
I have also attempted to add the MySQL ODBC 5.1 Driver so that I can export the data from SSMS but the driver does not appear in the export wizard's Destination options.
Can someone help me either get the MySQL ODBC Driver to show up in the SSMS export wizard destination options, or get MySQL Migration Tool to connect to the database and grab the data?
Thanks.
Try Data Import tool (ODBC format) in dbForge Studio for MySQL; or Data Export tool (ODBC format) in dbForge Data Studio for SQL Server.
I have used the SQL Examiner Suite. At first it did not work but after some digging found that the SQL being generated contained double-quotes around table names and columns (invalid SQL, basically). It does allow the user to edit the SQL before it is run so I had to go through the ~15 tables and delete the double-quotes around everything. Anywho - it works!!! Yay!
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).