I use Eclipse juno. I have mysql-connector-java-5.1.22-bin.jar in my buildpath and i try to establish a DB connection to my mysql database. Here is my code
public Connection getConnectionToDB() {
try {
Class.forName(driver);
Connection con = DriverManager.getConnection(url + dbName,
userName, password);
return con;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
When i debug it i found out the problem is at:
Class.forName(driver);
i also tried replacing it with:
Class.forName(driver).newInstance();
At this line, it breaks out to the exception and throws this exception:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at main.jdbc.BaseJdbc.getConnectionToDB(BaseJdbc.java:18)
at main.jdbc.UserDriverJdbc.queryUserById(UserDriverJdbc.java:15)
at main.drivers.UserDriver.findUserById(UserDriver.java:50)
at main.drivers.UserDriver.isLoginValid(UserDriver.java:56)
at main.controllers.LoginController.doPost(LoginController.java:33)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:164)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.__invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
The answer was quite tricky for me to find but i figure it out. It was ofcourse classpath problem.
If you ever encounter a problem like this and try to solve it inside eclipse, go to
eclipse -> window -> preferences -> java -> buildpath -> classpath
and add the
"mysql-connector-java-5.1.22-bin.jar"
as new variable. Name it whatever you like. Hope this helps.
You need to make sure you have the proper libraries and jar files loaded in your project. I dealt with this a lot when working with postgresql. I would think you're just missing the jar file.
This was my problem which was answered here:
SO Link
"If this code works in your J2SE it means you need to have a JAR file somewhere containing com.mysql.jdbc.Driver class (so called JDBC driver). This JAR needs to be visible in Tomcat. So, I would suggest to place mysql-jdbc.jar at physical location to /WEB-INF/lib directory of your project." From
I've been looking for a solution everywhere. Maybe this is not your solution, but using Eclipse i was exporting as a JAR file and got same exception, but then exported as "Runnable JAR"and it worked.
If you use netbeans then do the followings:
go to your application>>>libraries>>add jar (by right click)>> "mysql-connector-java-5.1.22-bin.jar"
In Your Eclipse Go to Windows->Preferences->Java->BuildPath->ClassPathVariables->New
Now Add Your Mysql-Connector jar file what you downloaded From Mvn repository or anywhere ...Now ApplyAndClose ...restart the server it will work...
Note: If You are using Servlet then use eclipse from the package not from the installer..If you will use the installer you will get lot of problem
Related
I'm trying to connect to a database I created with MySQL in my Java program, but it always fails.
For the sake of example, here is my code:
import java.sql.*;
public class Squirrel {
public static void main(String[] args) {
String user;
String password;
Connection connection;
Statement statement;
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(
"jdbc:mysql://localhost:3306", user, password);
statement = connection.createStatement();
// Other code
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
I am able to connect to the database from within IntelliJ and have added the mysql-connector-java-5.1.40.jar added to the project, but each time I run the program DriverManager.getConnection() throws this:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.Util.getInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2330)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2083)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:806)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:678)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:229)
at Squirrel.main(Squirrel.java:12)
Caused by: java.lang.NullPointerException
at com.mysql.jdbc.ConnectionImpl.getServerCharset(ConnectionImpl.java:2997)
at com.mysql.jdbc.MysqlIO.sendConnectionAttributes(MysqlIO.java:1934)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1863)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1226)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2253)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2284)
... 13 more
It might be because you're using an older version of the MySQL driver.
You should try using the newest version.
To get the newest version, you can check https://mvnrepository.com/artifact/mysql/mysql-connector-java
As of right now, the newest version is 8.0.11. You can download it here or add this to your pom.xml:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>
Update
Upon further investigation, it seems that it's because of a change that was introduced in MySQL 8.0.1:
The issue you reported is related to the changes introduced in MySQL
8.0.1 wrt the character sets and collations support, with the addition of now being 'utf8mb4' the default char set. Such changes broke the
way Connector/J initializes connections.
As you know this was fixed in Connector/J 5.1.41 and I'm sure you
already updated your library.
reference
Like mentionned above, an alternative fix to your problem would have been to use the 5.1.41 instead of 5.1.40.
Sounds like a potential version mismatch or outdated client. When you run it outside the IDE you may be pulling in the wrong version. I'd make sure the client is on the latest version or similar to the version used by the server.
I was importing the wrong version of mysql-connector. Changed the following
#Grab('mysql:mysql-connector-java:5.1.25')
to
#Grab('mysql:mysql-connector-java:5.1.46')
and everything worked as expected.
I've tried the above and it doesn't work. Then I checked in my .m2 folder and I noticed that there is a version 5.1.32 and version 8.0.19 mysql connector. However, when I tried to delete the folders, I'm not able to delete version 5.1.32 while the app is running. Obviously it means that version 5 is being in used somehow, eventhough in pom I've specified to use version 8.0.19.
So I just need to invalidate and restart from IntelliJ and voila.
If you call the IP address 127.0.0.1/localhost then you are communicating with the localhost – in principle, with your own computer.This issue also appears when you don't have localhost configured
For Linux systems
Add/Edit "127.0.0.1 localhost" under /etc/hosts if its missing.
For Windows system
Add/Edit under C:windows/system32/drivers/etc/hosts if its missing.
For more details on localhost
I'm trying to add a database-enabled JSP to an existing Tomcat 5.5 application (GeoServer 2.0.0, if that helps).
The app itself talks to Postgres just fine, so I know that the database is up, user can access it, all that good stuff. What I'm trying to do is a database query in a JSP that I've added. I've used the config example in the Tomcat datasource example pretty much out of the box. The requisite taglibs are in the right place -- no errors occur if I just have the taglib refs, so it's finding those JARs. The postgres jdbc driver, postgresql-8.4.701.jdbc3.jar is in $CATALINA_HOME/common/lib.
Here's the top of the JSP:
<%# taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<sql:query var="rs" dataSource="jdbc/mmas">
select current_validstart as ValidTime from runoff_forecast_valid_time
</sql:query>
The relevant section from $CATALINA_HOME/conf/server.xml, inside the <Host> which is in turn within <Engine>:
<Context path="/gs2" allowLinking="true">
<Resource name="jdbc/mmas" type="javax.sql.Datasource"
auth="Container" driverClassName="org.postgresql.Driver"
maxActive="100" maxIdle="30" maxWait="10000"
username="mmas" password="very_secure_yess_precious!"
url="jdbc:postgresql//localhost:5432/mmas" />
</Context>
These lines are the last in the tag in webapps/gs2/WEB-INF/web.xml:
<resource-ref>
<description>
The database resource for the MMAS PostGIS database
</description>
<res-ref-name>
jdbc/mmas
</res-ref-name>
<res-type>
javax.sql.DataSource
</res-type>
<res-auth>
Container
</res-auth>
</resource-ref>
Finally, the exception:
exception
org.apache.jasper.JasperException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
[...wads of ensuing goo elided]
The infamous java.sql.SQLException: No suitable driver found
This exception can have basically two causes:
1. JDBC driver is not loaded
In case of Tomcat, you need to ensure that the JDBC driver is placed in server's own /lib folder.
Or, when you're actually not using a server-managed connection pool data source, but are manually fiddling around with DriverManager#getConnection() in WAR, then you need to place the JDBC driver in WAR's /WEB-INF/lib and perform ..
Class.forName("com.example.jdbc.Driver");
.. in your code before the first DriverManager#getConnection() call whereby you make sure that you do not swallow/ignore any ClassNotFoundException which can be thrown by it and continue the code flow as if nothing exceptional happened. See also Where do I have to place the JDBC driver for Tomcat's connection pool?
Other servers have a similar way of placing the JAR file:
GlassFish: put the JAR file in /glassfish/lib
WildFly: put the JAR file in /standalone/deployments
2. Or, JDBC URL is in wrong syntax
You need to ensure that the JDBC URL is conform the JDBC driver documentation and keep in mind that it's usually case sensitive. When the JDBC URL does not return true for Driver#acceptsURL() for any of the loaded drivers, then you will also get exactly this exception.
In case of PostgreSQL it is documented here.
With JDBC, a database is represented by a URL (Uniform Resource Locator). With PostgreSQL™, this takes one of the following forms:
jdbc:postgresql:database
jdbc:postgresql://host/database
jdbc:postgresql://host:port/database
In case of MySQL it is documented here.
The general format for a JDBC URL for connecting to a MySQL server is as follows, with items in square brackets ([ ]) being optional:
jdbc:mysql://[host1][:port1][,[host2][:port2]]...[/[database]] » [?propertyName1=propertyValue1[&propertyName2=propertyValue2]...]
In case of Oracle it is documented here.
There are 2 URL syntax, old syntax which will only work with SID and the new one with Oracle service name.
Old syntax jdbc:oracle:thin:#[HOST][:PORT]:SID
New syntax jdbc:oracle:thin:#//[HOST][:PORT]/SERVICE
See also:
Where do I have to place the JDBC driver for Tomcat's connection pool?
How to install JDBC driver in Eclipse web project without facing java.lang.ClassNotFoundexception
How should I connect to JDBC database / datasource in a servlet based application?
What is the difference between "Class.forName()" and "Class.forName().newInstance()"?
Connect Java to a MySQL database
I've forgot to add the PostgreSQL JDBC Driver into my project (Mvnrepository).
Gradle:
// http://mvnrepository.com/artifact/postgresql/postgresql
compile group: 'postgresql', name: 'postgresql', version: '9.0-801.jdbc4'
Maven:
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.0-801.jdbc4</version>
</dependency>
You can also download the JAR and import to your project manually.
url="jdbc:postgresql//localhost:5432/mmas"
That URL looks wrong, do you need the following?
url="jdbc:postgresql://localhost:5432/mmas"
I faced the similar issue.
My Project in context is Dynamic Web Project(Java 8 + Tomcat 8) and error is for PostgreSQL Driver exception: No suitable driver found
It got resolved by adding Class.forName("org.postgresql.Driver") before calling getConnection() method
Here is my Sample Code:
try {
Connection conn = null;
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection("jdbc:postgresql://" + host + ":" + port + "/?preferQueryMode="
+ sql_auth,sql_user , sql_password);
} catch (Exception e) {
System.out.println("Failed to create JDBC db connection " + e.toString() + e.getMessage());
}
I found the followig tip helpful, to eliminate this issue in Tomcat -
be sure to load the driver first doing a Class.forName("
org.postgresql.Driver"); in your code.
This is from the post - https://www.postgresql.org/message-id/e13c14ec050510103846db6b0e#mail.gmail.com
The jdbc code worked fine as a standalone program but, in TOMCAT it gave the error -'No suitable driver found'
No matter how old this thread becomes, people would continue to face this issue.
My Case: I have the latest (at the time of posting) OpenJDK and maven setup. I had tried all methods given above, with/out maven and even solutions on sister posts on StackOverflow. I am not using any IDE or anything else, running from bare CLI to demonstrate only the core logic.
Here's what finally worked.
Download the driver from the official site. (for me it was MySQL https://www.mysql.com/products/connector/). Use your flavour here.
Unzip the given jar file in the same directory as your java project. You would get a directory structure like this. If you look carefully, this exactly relates to what we try to do using Class.forName(....). The file that we want is the com/mysql/jdbc/Driver.class
Compile the java program containing the code.
javac App.java
Now load the director as a module by running
java --module-path com/mysql/jdbc -cp ./ App
This would load the (extracted) package manually, and your java program would find the required Driver class.
Note that this was done for the mysql driver, other drivers might require minor changes.
If your vendor provides a .deb image, you can get the jar from /usr/share/java/your-vendor-file-here.jar
Summary:
Soln2 (recommend)::
1 . put mysql-connector-java-8.0.28.jar file in the <where you install your Tomcat>/lib.
Soln1::
1 . put mysql-connector-java-8.0.28.jar file in the WEB-INF/lib.
2 . use Class.forName("com.mysql.cj.jdbc.Driver"); in your Servlet Java code.
Soln1 (Ori Ans) //-20220304
In short:
make sure you have the mysql-connector-java-8.0.28.jar file in the WEB-INF/lib
make sure you use the Class.forName("com.mysql.cj.jdbc.Driver");
additional notes (not important), base on my trying (could be wrong)::
1.1 putting the jar directly inside the Java build path doesnt work
1.2. putting the jar in Data management > Driver Def > MySQL JDBC Driver > then add it as library to Java Build path doesnt work.
1.3 => it has to be inside the WEB-INF/lib (I dont know why)
1.4 using version mysql-connector-java-8.0.28.jar works, only version 5.1 available in Eclipse MySQL JDBC Driver setting doesnt matter, ignore it.
<see How to connect to MySql 8.0 database using Eclipse Database Management Perspective >
Class.forName("com.mysql.cj.jdbc.Driver");
Class.forName("com.mysql.jdbc.Driver");
both works,
but the Class.forName("com.mysql.jdbc.Driver"); is deprecated.
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
<see https://www.yawintutor.com/no-suitable-driver-found-for-jdbcmysql-localhost3306-testdb/ >
If you want to connect to a MySQL database, you can use the type-4 driver named Connector/} that's available for free from the MySQL website. However, this driver is typically included in Tomcat's lib directory. As a result, you don't usually need to download this driver from the MySQL site.
-- Murach’s Java Servlets and JSP
I cant find the driver in Tomcat that the author is talking about, I need to use the mysql-connector-java-8.0.28.jar.
<(striked-out) see updated answer soln2 below>
If you're working with an older version of Java, though, you need to use the forName method of the Class class to explicitly load the driver before you call the getConnection method
Even with JDBC 4.0, you sometimes get a message that says, "No suitable driver found." In that case, you can use the forName method of the Class class to explicitly load the driver. However, if automatic driver loading works, it usually makes sense to remove this method call from your code.
How to load a MySQL database driver prior to JDBC 4.0
Class.forName{"com.mysql.jdbc.Driver");
-- Murach’s Java Servlets and JSP
I have to use Class.forName("com.mysql.cj.jdbc.Driver"); in my system, no automatic class loading. Not sure why.
<(striked-out) see updated answer soln2 below>
When I am using a normal Java Project instead of a Dynamic Web Project in Eclipse,
I only need to add the mysql-connector-java-8.0.28.jar to Java Build Path directly,
then I can connect to the JDBC with no problem.
However, if I am using Dynamic Web Project (which is in this case), those 2 strict rules applies (jar position & class loading).
<see TOMCAT ON ECLIPSE java.sql.SQLException: No suitable driver found for jdbc:mysql >
Soln2 (Updated Ans) //-20220305_12
In short:
1 . put mysql-connector-java-8.0.28.jar file in the <where you install your Tomcat>/lib.
eg: G:\pla\Java\apache-tomcat-10.0.16\lib\mysql-connector-java-8.0.28.jar
(and for an Eclipse Dynamic Web Project, the jar will then be automatically put inside in your project's Java build path > Server Runtime [Apache Tomcat v10.0].)
Additional notes::
for soln1::
put mysql-connector-java-8.0.28.jar file in the WEB-INF/lib.
use Class.forName("com.mysql.cj.jdbc.Driver"); in your Servlet Java code.
this will create an WARNING:
WARNING: The web application [LearnJDBC] appears to have started a thread named [mysql-cj-abandoned-connection-cleanup] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
<see The web application [] appears to have started a thread named [Abandoned connection cleanup thread] com.mysql.jdbc.AbandonedConnectionCleanupThread >
and that answer led me to soln2.
for soln2::
put mysql-connector-java-8.0.28.jar file in the <where you install your Tomcat>/lib.
this will create an INFO:
INFO: 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.
you can just ignore it.
<see How to fix "JARs that were scanned but no TLDs were found in them " in Tomcat 9.0.0M10 >
(you should now understand what Murach’s Java Servlets and JSP was talking about: the jar in Tomcat/lib & the no need for Class.forName("com.mysql.cj.jdbc.Driver");)
to kinda fix it //-20220307_23
Tomcat 8.5. Inside catalina.properties, located in the /conf directory set:
tomcat.util.scan.StandardJarScanFilter.jarsToSkip=\*.jar
How to fix JSP compiler warning: one JAR was scanned for TLDs yet contained no TLDs?
It might be worth noting that this can also occur when Windows blocks downloads that it considers to be unsafe. This can be addressed by right-clicking the jar file (such as ojdbc7.jar), and checking the 'Unblock' box at the bottom.
Windows JAR File Properties Dialog:
As well as adding the MySQL JDBC connector ensure the context.xml (if not unpacked in the Tomcat webapps folder) with your DB connection definitions are included within Tomcats conf directory.
A very silly mistake which could be possible resulting is adding of space at the start of the JDBC URL connection.
What I mean is:-
suppose u have bymistake given the jdbc url like
String jdbcUrl=" jdbc:mysql://localhost:3306/web_customer_tracker?useSSL=false&serverTimeZone=UTC";
(Notice there is a space in the staring of the url, this will make the error)
the correct way should be:
String jdbcUrl="jdbc:mysql://localhost:3306/web_customer_tracker?useSSL=false&serverTimeZone=UTC";
(Notice no space in the staring, you may give space at the end of the url but it is safe not to)
Run java with CLASSPATH environmental variable pointing to driver's JAR file, e.g.
CLASSPATH='.:drivers/mssql-jdbc-6.2.1.jre8.jar' java ConnectURL
Where drivers/mssql-jdbc-6.2.1.jre8.jar is the path to driver file (e.g. JDBC for for SQL Server).
The ConnectURL is the sample app from that driver (samples/connections/ConnectURL.java), compiled via javac ConnectURL.java.
I was using jruby, in my case I created under config/initializers
postgres_driver.rb
$CLASSPATH << '~/.rbenv/versions/jruby-1.7.17/lib/ruby/gems/shared/gems/jdbc-postgres-9.4.1200/lib/postgresql-9.4-1200.jdbc4.jar'
or wherever your driver is, and that's it !
I had this exact issue when developing a Spring Boot application in STS, but ultimately deploying the packaged war to WebSphere(v.9). Based on previous answers my situation was unique. ojdbc8.jar was in my WEB-INF/lib folder with Parent Last class loading set, but always it says it failed to find the suitable driver.
My ultimate issue was that I was using the incorrect DataSource class because I was just following along with online tutorials/examples. Found the hint thanks to David Dai comment on his own question here: Spring JDBC Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]
Also later found spring guru example with Oracle specific driver: https://springframework.guru/configuring-spring-boot-for-oracle/
Example that throws error using org.springframework.jdbc.datasource.DriverManagerDataSource based on generic examples.
#Config
#EnableTransactionManagement
public class appDataConfig {
\* Other Bean Defs *\
#Bean
public DataSource dataSource() {
// configure and return the necessary JDBC DataSource
DriverManagerDataSource dataSource = new DriverManagerDataSource("jdbc:oracle:thin:#//HOST:PORT/SID", "user", "password");
dataSource.setSchema("MY_SCHEMA");
return dataSource;
}
}
And the corrected exapmle using a oracle.jdbc.pool.OracleDataSource:
#Config
#EnableTransactionManagement
public class appDataConfig {
/* Other Bean Defs */
#Bean
public DataSource dataSource() {
// configure and return the necessary JDBC DataSource
OracleDataSource datasource = null;
try {
datasource = new OracleDataSource();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
datasource.setURL("jdbc:oracle:thin:#//HOST:PORT/SID");
datasource.setUser("user");
datasource.setPassword("password");
return datasource;
}
}
I was having the same issue with mysql datasource using spring data that would work outside but gave me this error when deployed on tomcat.
The error went away when I added the driver jar mysql-connector-java-8.0.16.jar to the jres lib/ext folder
However I did not want to do this in production for fear of interfering with other applications. Explicity defining the driver class solved this issue for me
spring.datasource.driver-class-name: com.mysql.cj.jdbc.Driver
You will get this same error if there is not a Resource definition provided somewhere for your app -- most likely either in the central context.xml, or individual context file in conf/Catalina/localhost. And if using individual context files, beware that Tomcat freely deletes them anytime you remove/undeploy the corresponding .war file.
For me the same error occurred while connecting to postgres while creating a dataframe from table .It was caused due to,the missing dependency. jdbc dependency was not set .I was using maven for the build ,so added the required dependency to the pom file from maven dependency
jdbc dependency
For me adding below dependency to pom.xml file just solved like magic! I had no mysql connector dependency and even adding mssql jdbc jar file to build path did not work either.
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>9.4.0.jre11</version>
</dependency>
In my case I was working on a Java project with Maven and encountered this error.
In your pom.xml file make sure you have this dependencies
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>
</dependencies>
and where you create connection have something like this
public Connection createConnection() {
try {
String url = "jdbc:mysql://localhost:3306/yourDatabaseName";
String username = "root"; //your my sql username here
String password = "1234"; //your mysql password here
Class.forName("com.mysql.cj.jdbc.Driver");
return DriverManager.getConnection(url, username, password);
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
faced same issue. in my case ':' colon before '//' (jdbc:mysql://localhost:3306/dbname) was missing, and it just fixed the problem.
make sure : and // are placed properly.
I ran into the same error. In my case, the JDBC URL was correct, but the issue was with classpath. However, adding MySQL connector's JAR file to the -classpath or -cp (or, in the case of an IDE, as a library) doesn't resolve the issue. So I will have to move the JAR file to the location of Java bytecode and run java -cp :mysql_connector.jar to make this work. If someone runs into the same issue as mine, I'm leaving this here.
I encountered this issue by putting a XML file into the src/main/resources wrongly, I deleted it and then all back to normal.
What is wrong with the code there are lots of error while debugging. I am writing a code for a singleton class to connect with the database mysql.
Here is my code
package com.glomindz.mercuri.util;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
public class MySingleTon {
String url = "jdbc:mysql://localhost:3306/";
String dbName = "test";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "";
private static MySingleTon myObj;
private Connection Con ;
private MySingleTon() {
System.out.println("Hello");
Con= createConnection();
}
#SuppressWarnings("rawtypes")
public Connection createConnection() {
Connection connection = null;
try {
// Load the JDBC driver
Class driver_class = Class.forName(driver);
Driver driver = (Driver) driver_class.newInstance();
DriverManager.registerDriver(driver);
connection = DriverManager.getConnection(url + dbName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
return connection;
}
/**
* Create a static method to get instance.
*/
public static MySingleTon getInstance() {
if (myObj == null) {
myObj = new MySingleTon();
}
return myObj;
}
public static void main(String a[]) {
MySingleTon st = MySingleTon.getInstance();
}
}
I am new to java. Please help.
It seems the mysql connectivity library is not included in the project. Solve the problem following one of the proposed solutions:
MAVEN PROJECTS SOLUTION
Add the mysql-connector dependency to the pom.xml project file:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
</dependency>
Here you are all the versions: https://mvnrepository.com/artifact/mysql/mysql-connector-java
ALL PROJECTS SOLUTION
Add the jar library manually to the project.
Right Click the project -- > build path -- > configure build path
In Libraries Tab press Add External Jar and Select your jar.
You can find zip for mysql-connector here
Explanation:
When building the project, java throws you an exception because a file (the com.mysql.jdbc.Driver class) from the mysql connectivity library is not found. The solution is adding the library to the project, and java will find the com.mysql.jdbc.Driver
If you got the error in your IDE(compile-time error), you need to add your mysql-connector jar file to your libs and add this to your referenced library of project too.
If you get this error when you are running it, then probably its because you have not included mysql-connector JAR file to your webserver's lib folder.
Add mysql-connector-java-5.1.25-bin.jar to your classpath and also to your webserver's lib directory. Tomcat lib path is given as an example Tomcat 6.0\lib
Every one has written an answer but I am still surprised that nobody actually answered it by using the best simple way.
The people answer that include the jar file. But, the error will still occur.
The reason for that is, the jar is not deployed when the project is run. So, what we need to do is, tell the IDE to deploy this jar also.
The people here has answered so many times that put that jar file in the lib folder of WEB-INF. That seems okay, but why do it manually. There is simple way. Check the below steps:
Step 1: If you haven't referenced the jar file into the project then, reference it like this.
Right click on the project and go to the project properties.
Then, go to the java build path, then add external jar file via that.
But this will still not solve the problem because adding the external jar via build path only helps in compiling the classes, and the jar will not be deployed when you run the project. For that follow this step
Right click on the project and go to the project properties.
Then, go to the Deployment Assembly then press Add , then go to the java build path entries and add your libraries whether it is jstl, mysql or any other jar file. add them to deployment.
Below are the two pictures which display it.
For Gradle-based projects you need a dependency on MySQL Java Connector:
dependencies {
compile 'mysql:mysql-connector-java:6.0.+'
}
You will have to include driver jar for MySQL MySQL Connector Jar in your classpath.
If you are using Eclipse:
How to add dependent libraries in Eclipse
If you are using command line include the path to the driver jar using the -cp parameter of java.
java -cp C:\lib\* Main
check for jar(mysql-connector-java-bin) in your classpath download from here
JDBC API mostly consists of interfaces which work independently of any database. A database specific driver is required for each database which implements the JDBC API.
First download the MySQL connector jar from www.mysql.com, then:
Right Click the project -- > build path -- > configure build path
In the libraries tab press Add External Jar and select your jar.
For Maven based projects you need a dependency.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
The driver connector is not in your build path. Configure the build path and point it to the 'mysql-connector-java-5.1.25-bin.jar' (check the version which you are using). Alternatively you can use maven :D
In the project into the folder Libraries-->right click --> Add Library --> Mysqlconnector 5.1
For IntelliJ Idea, go to your project structure (File, Project Structure), and add the mysql connector .jar file to your global library. Once there, right click on it and chose 'Add to Modules'. Hit Apply / OK and you should be good to go.
This needs to be used as of 2021
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.21</version>
</dependency>
Trivial as it may seem in my case netbeans version maven project 7.2.1 was different. There is a folder in the project called dependencies. Right click and then it brings up a popup window where you can search for packages. In the query area put
mysql-connector
It will bring up the matches (it seems it does this against some repository). Double click then install.
It is because the WEB-INF folder does not exist at the location in the sub directory in the error. You either compile the application to use the WEB-INF folder under public_html OR copy the WEB-INF folder in sub folder as in the error above.
The exception can also occur because of the class path not being defined.
After hours of research and literally going through hundreds of pages, the problem was that the class path of the library was not defined.
Set the class path as follows in your windows machine
set classpath=path\to\your\jdbc\jar\file;.
I Understood your problem add this dependency in your pom.xml your problem will be solved,
https://mvnrepository.com/artifact/mysql/mysql-connector-java/5.1.38
If you are using tomcat then along with project directory you should also copy the database connector jar file to tomcat/lib. this worked for me
I'm developing a simple JavaFX11 application with SQLite Database in Eclipse IDE. To generate report I added Jasper jars. Suddenly it throws "THIS" error.
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
It was running good (BEFORE THIS ADDITION). But suddenly!
I'm not using maven or other managers for this simple application. I'm adding jars manually.
I created "User Library" and added my jars from external folders.
PROBLEM OCCURING AREA:
My "User Library" are marked as system library. I just removed the marking. Now its not a system library. "NOW MY PROJECT WORKING GOOD".
DEBUG MYSELF: Tried other things:
AT RUN CONFIGURATION: Try, removing library and add jars one-by-one and see. - here you have to delete all jars one by one, there is no select all and remove in eclipse right now in run configuration. So the error messages changes form one jars to another.
Hope this helps someone.
I was also facing the same problem
Download mysql-connector-java jar file
paste it in the C:\Program Files\Apache Software Foundation\Tomcat 9.0\lib
Hope this work for you also !!
Finally
I solved by two steps :
1 - add the below to pom.xml
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.0.8</version>
</dependency>
2 - Download jar file from this URL:https://mvnrepository.com/artifact/mysql/mysql-connector-java/5.0.8
after that put it in your tomcat/lib folder.
I was having the same issue. I was using intellijj IDE for creating the MySQL connection.
Steps to fix it:
Download: mysql-connector.jar( I used 8.0.29).
Go to "file-->project structure -->Libraries-->Click on plus button and select java and select the jar file you downloaded in step 1".
Check the jar file is showing under "External Libraries directory"
4. Now try to create the connection. It will work.
I used this code for creating MySQL connection:
void createConnection() throws SQLException, ClassNotFoundException {
Connection connection=null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
connection= DriverManager.getConnection("jdbc:mysql://localhost:3306/candelete"
,"root","");
System.out.println("Connection created");
System.out.println("hashcode is: "+connection.hashCode());
}
finally {
System.out.println("here");
System.out.println("hashcode is: "+connection.hashCode());
connection.close();
System.out.println("hashcode now: "+connection.hashCode());
}
}
when I'm trying to run test I have issue as on screenshot, where am I wrong?
thx
"C:\Program Files\Java\jdk1.8.0_11\bin\java" -ea -Didea.launcher.port=7537 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 14.0\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 14.0\plugins\testng\lib\testng-plugin.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\zipfs.jar;C:\Users\vol.7\Downloads\aaaaaa\src\main\resources\target\test-classes;C:\Users\vol.7\Downloads\aaaaaa\target\classes;C:\Users\vol.7\.m2\repository\org\seleniumhq\selenium\selenium-chrome-driver\2.44.0\selenium-chrome-driver-2.44.0.jar;C:\Users\vol.7\.m2\repository\org\seleniumhq\selenium\selenium-remote-driver\2.44.0\selenium-remote-driver-2.44.0.jar;C:\Users\vol.7\.m2\repository\cglib\cglib-nodep\2.1_3\cglib-nodep-2.1_3.jar;C:\Users\vol.7\.m2\repository\com\google\code\gson\gson\2.3\gson-2.3.jar;C:\Users\vol.7\.m2\repository\org\seleniumhq\selenium\selenium-api\2.44.0\selenium-api-2.44.0.jar;C:\Users\vol.7\.m2\repository\org\apache\httpcomponents\httpclient\4.3.4\httpclient-4.3.4.jar;C:\Users\vol.7\.m2\repository\org\apache\httpcomponents\httpcore\4.3.2\httpcore-4.3.2.jar;C:\Users\vol.7\.m2\repository\commons-logging\commons-logging\1.1.3\commons-logging-1.1.3.jar;C:\Users\vol.7\.m2\repository\commons-codec\commons-codec\1.6\commons-codec-1.6.jar;C:\Users\vol.7\.m2\repository\com\google\guava\guava\18.0\guava-18.0.jar;C:\Users\vol.7\.m2\repository\net\java\dev\jna\jna\3.4.0\jna-3.4.0.jar;C:\Users\vol.7\.m2\repository\net\java\dev\jna\platform\3.4.0\platform-3.4.0.jar;C:\Users\vol.7\.m2\repository\org\testng\testng\6.9.9\testng-6.9.9.jar;C:\Users\vol.7\.m2\repository\junit\junit\4.10\junit-4.10.jar;C:\Users\vol.7\.m2\repository\org\hamcrest\hamcrest-core\1.1\hamcrest-core-1.1.jar;C:\Users\vol.7\.m2\repository\com\beust\jcommander\1.48\jcommander-1.48.jar;C:\Users\vol.7\.m2\repository\org\apache\ant\ant\1.7.0\ant-1.7.0.jar;C:\Users\vol.7\.m2\repository\org\apache\ant\ant-launcher\1.7.0\ant-launcher-1.7.0.jar;C:\Users\vol.7\.m2\repository\org\yaml\snakeyaml\1.15\snakeyaml-1.15.jar;C:\Users\vol.7\.m2\repository\org\beanshell\bsh\2.0b4\bsh-2.0b4.jar;C:\Users\vol.7\.m2\repository\org\seleniumhq\selenium\selenium-firefox-driver\2.44.0\selenium-firefox-driver-2.44.0.jar;C:\Users\vol.7\.m2\repository\commons-io\commons-io\2.4\commons-io-2.4.jar;C:\Users\vol.7\.m2\repository\org\apache\commons\commons-exec\1.1\commons-exec-1.1.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 14.0\plugins\testng\lib\testng.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 14.0\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.testng.RemoteTestNGStarter -port 54806 -usedefaultlisteners false -socket54807 -temp C:\Users\vol.7\AppData\Local\Temp\idea_testng36.tmp
org.testng.TestNGException: Cannot instantiate class Aaas at
org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:40)
at
org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:382)
at
org.testng.internal.ClassHelper.createInstance(ClassHelper.java:295)
at
org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:118)
at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:183) at
org.testng.internal.TestNGClassFinder.(TestNGClassFinder.java:128)
at org.testng.TestRunner.initMethods(TestRunner.java:416) at
org.testng.TestRunner.init(TestRunner.java:242) at
org.testng.TestRunner.init(TestRunner.java:212) at
org.testng.TestRunner.(TestRunner.java:166) at
org.testng.remote.RemoteTestNG$1.newTestRunner(RemoteTestNG.java:143)
at
org.testng.remote.RemoteTestNG$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG.java:272)
at
org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:587)
at org.testng.SuiteRunner.init(SuiteRunner.java:161) at
org.testng.SuiteRunner.(SuiteRunner.java:114) at
org.testng.TestNG.createSuiteRunner(TestNG.java:1290) at
org.testng.TestNG.createSuiteRunners(TestNG.java:1277) at
org.testng.TestNG.runSuitesLocally(TestNG.java:1131) at
org.testng.TestNG.run(TestNG.java:1048) at
org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:112) at
org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:205) at
org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:176) at
org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:125) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483) at
com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.reflect.InvocationTargetException at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at
org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:29)
... 27 more Caused by: java.lang.IllegalStateException: The path to
the driver executable must be set by the webdriver.chrome.driver
system property; for more information, at
com.google.common.base.Preconditions.checkState(Preconditions.java:197)
at
org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105)
at
org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:89)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:117)
at Aaas.(Aaas.java:11) ... 32 more
Process finished with exit code 0
In your code it looks like you did 2 mistakes.
First thing...
Please remove the instantiation of "new ChromeDriver()" when a reference of type WebDriver created in class.
Instead create a referece:
public WebDriver driver;
Then instantiate the chrome driver inside the test case-->
#Test
public void testMethod(){
//Here, Before the instantiation just use setProperty method
System.setProperty("key","path to chrome driver.exe");
driver=new ChromeDriver();
}
and the Second thing is...
make sure the relative path is correct to chromedriver.exe file...
Use absolute path to the chrome driver.
You're creating the new ChromeDriver in your (implicit) constructor before you're calling: System.setProperty("webdriver.chrome.driver", ...)
You need to set the property before creating any Drivers (same applies to IE, Opera, etc.)
One approach is to create a static { ... } block and move your setting of System properties there. That'll get called before you create your Driver.
It looks like you are not given complete chromediver.exe path. More over over calling chrome driver before system.set property. please set system property first then call chrome driver..
System.setProperty("webdriver.chrome.driver", "E:\\selenium_setups\\chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
Thank You,
Murali
You haven't set a location for the chromedriver binary. Edit the configuration of your test by clicking on the drop down box in the top bar. Then add to your VM options a path for the chromedriver binary:
-Dwebdriver.chrome.driver=<ABSOLUTE_PATH_TO>/chromedriver
Since you are using a maven project you may find this maven plugin useful:
https://github.com/Ardesco/selenium-standalone-server-plugin
It will download the driver binaries for you and set up the correct system properties when running your tests through maven. There is a template that uses it here that you can use as an example of how to get it configured:
https://github.com/Ardesco/Selenium-Maven-Template
*Note* Running the test through intelliJ is not the same as running it through maven. System properties that are only set through maven will not have been set in IntelliJ when you run a test through the IDE. This is why you need to edit your test configuration if you have already set the correct System Properties through maven.
My GWT application does not seem to find mysql-connector-java-5.1.22-bin.jar.
Im using the Google App Engine.
I have set the jar in Project->RIghtClick->Properties->Java Build Path->Libraries->mysql-connector-java-5.1.22-bin.jar. I also added the "MySQL JDBC Driver". The $CLASSPATH is set correctly too (i dont think it matters because Im running the application in Eclipse).
I have tested the same code on command line and it works like a charm.
$ java -cp ~/mysql-connector-java-5.1.22/mysql-connector-java-5.1.22-bin.jar:. JDBCExample
-------- MySQL JDBC Connection Testing ------------
MySQL JDBC Driver Registered!
You made it, take control your database now!
When I run the Web Application in Eclipse, I get this
Exception:
-------- MySQL JDBC Connection Testing ------------
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
ClassNotFound - Where is your MySQL JDBC Driver?com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:207)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at com.startupweekend.server.GreetingServiceImpl.readDB(GreetingServiceImpl.java:65)
at com.startupweekend.server.GreetingServiceImpl.greetServer(GreetingServiceImpl.java:21)
Code:
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.out.println("ClassNotFound - Where is your MySQL JDBC Driver?" + e.getMessage());
e.printStackTrace();
return;
}
I'm not completely sure, but you should just put the mysql driver in your WEB-INF/lib folder and then right click -> add to build path. That should make it work.
Bear in mind that in GAE you cannot use common relational databases, you can only use Google CloudSQL.
You don't need the App Engine, just use GWT compile when you're ready for your war file. In any case, right click project folder -> properties -> Google -> App Engine -> uncheck 'Use Google App Engine'. Make sure the mysql-connector is in your lib folder. Enjoy your favorite relational database, and more.
Cheers