I am trying to use the Squirrel SQL client to connect to a H2 server instance.
The problem I am facing is that when I hit the "connect" button of the server I want to connect to, then I am getting a:
ClassNotFoundException: org.h2.Driver
I thought it was because h2.jar was not in the classpath. Then I edited squirrel-sql.bar to try two things.
The first thing I tried is to add the JAR into the PATH like this:
SET PATH=%PATH%;C:\Program Files\squirrel-sql-3.5.3\plugins\h2.jar
Then I restarted Squirrel. Same error.
Then I tried adding:
set TMP_CP=%TMP_CP%;"C:\Program Files\squirrel-sql-3.5.3\plugins\h2.jar"
Then I restarted Squirrel. Same error.
When I look at the console, I can see that h2.jar is in the PATH and/or the SQUIRREL_CP but the same error occurs all the time.
I am wondering if I am not forgetting something bout how to install/configure SQuirrel and/or H2?
Rather than modifying the batch files every time you use a different driver just modify the drivers classpath through the GUI.
Double click on the appropriate driver in the Drivers tab then click on the "Extra Class Path" tab and add the driver jar.
You can find more information under "How to connect to a Database" in the SQuirreL section in the Help file. Press F1 in SQuirreL to see the Help file. You can see a screenshot at http://www.squirrelsql.org/screenshots/driver.html
I found the issue to my problem. I was linking to the h2 file in Squirrel SQL. However, I had to link to the h2 file from the H2 application... What I did to solve my issue is to add a line to the addpath.bat file such that the file looks like:
set TMP_CP=%TMP_CP%;%1
set TMP_CP=%TMP_CP%;"C:\Program Files (x86)\H2\bin\h2-1.4.181.jar"
Then I restarted Squirrel SQL and everything was working as expected!
I'm listing the exact steps I followed to add the driver as even though Colin Bell has already given a good answer, without following the final step 4. I still couldn't get this to work.
Download http://www.h2database.com/automated/h2-latest.jar and save it somewhere, in my case ~/drivers/h2-latest.jar
Edit the existing h2 driver.
On the 'Extra Class Path' tab add the driver
Click 'List Drivers' - org.h2.Driver should appear in the 'Class Name' field (as detailed in the link from Colin's answer: http://www.squirrelsql.org/screenshots/driver.html)
I was missing the final step of clicking 'List Drivers' since it already had org.h2.Driver in the 'Class Name' before I tried to add it. But without this step it was still giving the error:
Could not find class org.h2.Driver in neither the Java class path nor the Extra class path of the H2 driver definition:
java.lang.ClassNotFoundException: org.h2.Driver
Related
When I try to do the flyway tutorial for Java, I wanted to check the flyway_schema_history table stored in the embedded H2 database. The database file (foobar.mv.db) is created at project target folder with the configuration
<url>jdbc:h2:file:./target/foobar</url>
But I cannot open the database from browser (localhost:8082). I had to copy the database file to my user home dir because that's the default location that H2 console uses. How should I specify the jdbc URL in order to have the console pointing to the project target folder? The default URL is jdbc"h2:file:~/foobar. I want to know how to make it point to my project, say at C:\Users\scong\IdeaProjects\my-flyway-migration-service. foobar.mv.db file is created at C:\Users\scong\IdeaProjects\my-flyway-migration-service\target with above configuration.
The answer in the post What is the jdbc connection string for h2 database? actually doesn't work for me. The console complains the colon character after the drive letter (C:) in the path. I tried to use the below absolute path,
jdbc:h2:file://localhost/C:/Users/scong/IdeaProjects/my-flyway-migration-service/target/foobar
It gave the below error
General error: "java.nio.file.InvalidPathException: Illegal character [:] in path at index 13: //localhost/C:/Users/scong/IdeaProjects/my-flyway-migration-service/target/foobar" [50000-214] HY000/50000 (Help)
so I'm trying to create a custom webdriver (as in (down)load the normal driver but use custom profile settings) to get it to open any tab with a popped-out DevTools window (set to "Console").
I figured I could do that by setting up such a preference file by just interacting with my own installed Chrome version and copying my preferences to another folder, then let the Selenium WebDriver load its preferences from that folder.
But when I tried starting the WebDriver using this:
options.addArguments("--profile-directory=\"Default\"");
options.addArguments("--user-data-dir=./temp-selenium");
... it always shows an error (in german, roughly translated to):
Google Chrome can't read or write in the following directory: ./temp-selenium
Removing the second line completely just starts a Chome window with a user profile selection prompt. Setting up a file path to something like AppData doesn't work because then I get the following error:
Could not remove old devtools port file. Perhaps the given user-data-dir at "myFilePath\User Data" is still attached to a running Chrome ...
By the way, why I'm doing this: I just want to SEE the console logs while testing stuff. Can't imagine it's actually THIS difficult to get to it. My tests are way too fast to manually open the console in time and I need to find a bug that happens every 100 tries. Opening the console 100 times is just way too tedious.
Anyone have an idea?
Whenever I run the DS job I am getting following issue
"Error loading connector library cctera12.dll. The specified module could not be found.
(CC_LoadedConnector::loadLibrary, file CC_ConnectorFactory.cpp, line 1,536)"
But cctera12.dll this library is present in dscomponents and also mentioned that path in system path.
Please help to solve this issue , thanks .
here are few steps you can follow.
ensure that LD_LIBRARY_PATH is having link to the DSComponents/bin folder.
With your #tags i assume that you are facing issue with Teradata database so make sure that the LD_LIBRARY_PATH is updated with Teradata home location. If its oracle db ORACLE_HOME location should be present in library.
you may need to restart your datastage server and services
This question already has answers here:
The infamous java.sql.SQLException: No suitable driver found
(21 answers)
Closed 7 years ago.
Using Java, I get this error when attempting to connect to a mysql database:
java.sql.SQLException: No suitable driver found for
jdbc:mysql://localhost:3306/mysql at
java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at MyTest1.main(MyTest1.java:28)
I'm using the mysql-connector-java-5.1.18-bin.jar driver. It is in my build path. I have restarted MySQL. I've also logged on from the command line with root and no password and it connected fine. I'm not currently seeing a port 3306 in netstat. Previously I was getting a different error (I didn't change the code). The error was "jdbc mysql Access denied for user 'root'#'localhost password NO"
try {
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
String url = "jdbc:mysql://localhost:3306/mysql";
Connection con = DriverManager.getConnection(url, "root", "");
}
catch (Exception e){
e.printStackTrace();
}
In this particular case (assuming that the Class#forName() didn't throw an exception; your code is namely continuing with running instead of throwing the exception), this SQLException means that Driver#acceptsURL() has returned false for any of the loaded drivers.
And indeed, your JDBC URL is wrong:
String url = "'jdbc:mysql://localhost:3306/mysql";
Remove the singlequote:
String url = "jdbc:mysql://localhost:3306/mysql";
See also:
Mini tutorial on MySQL + JDBC connectivity
You have to set classpath for mysql-connector.jar
In eclipse, use the build path
If you are developing any web app, you have to put mysql-connector to the lib folder of WEB-INF Directory of your web-app
When using Netbean, go under project tab and click the dropdown button there to select Libraries folder. Right Click on d Library folder and select 'Add JAR/Folder'. Locate the mysql-connectore-java.*.jar file where u have it on ur system.
This worked for me and I hope it does for u too.
Revert if u encounter any problem
This error happened to me, generally it'll be a problem due to not including the mysql-connector.jar in your eclipse project (or your IDE).
In my case, it was because of a problem on the OS.
I was editing a table in phpmyadmin, and mysql hung, I restarted Ubuntu. I cleaned the project without being successful. This morning, when I've tried the web server, it work perfectly the first time.
At the first reboot, the OS recognized that there was a problem, and after the second one, it was fixed. I hope this will save some time to somebody that "could" have this problem!
A typographical error in the string describing the database driver can also produce the error.
A string specified as:
"jdbc:mysql//localhost:3307/dbname,"usrname","password"
can result in a "no suitable driver found" error. The colon following "mysql" is missing in this example.
The correct driver string would be:
jdbc:mysql://localhost:3307/dbname,"usrname","password"
i had same problem i fix this using if developing jsp, put mysql connetor into WEB-INF->lib folder after puting that in eclipse right click and go build-path -> configure build patha in library tab add external jar file give location where lib folder is
Just telling my resolution: in my case, the libraries and projects weren't being added automatically to the classpath (i don't know why), even clicking at the "add to build path" option. So I went on run -> run configurations -> classpath and added everything I needed through there.
( If your url is correct and still get that error messege )
Do following steps to setup the Classpath in netbeans,
Create a new folder in your project workspace and add the downloaded .jar file(eg:- mysql-connector-java-5.1.35-bin.jar )
Right click your project > properties > Libraries > ADD jar/Folder
Select the jar file in that folder you just make. And click OK.
Now you will see that .jar file will be included under the libraries. Now you will not need to use the line, Class.forName("com.mysql.jdbc.Driver"); also.
If above method did not work, check the mysql-connector version (eg:- 5.1.35) and try a newer or a suitable version for you.
There is a VERY similar question to mine but in my case I don't have any duplicate jars in my build path, so the solution does not work for me. I've searched google for a couple of hours now, but none of the solutions I've found there actually resolve my issue. I'm creating a web site with some database connectivity for a homework. I'm using a MySQL database, developing in Eclipse and running on Windows.
I keep getting java.lang.ClassNotFoundException: com.mysql.jdbc.Driver with the following code:
import java.sql.*;
//...
public void someMethodInMyServlet(PrintWriter out)
{
Connection connection = null;
PreparedStatement query = null;
try {
out.println("Create the driver instance.<br>");
Class.forName("com.mysql.jdbc.Driver").newInstance();
out.println("Get the connection.<br>");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "secret");
query = connection.prepareStatement( "SELECT * FROM customers");
//...
} catch (Exception e)
{
out.println(e.toString()+"<br>");
}
}
//...
When I run the above code I get the following output:
Create the driver instance.
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
It doesn't get past the Class.forName... line and I can't figure out why! Here is what I did:
Download mysql-connector.
Put it in my MySQL folder C:\Program Files\MySQL\mysql-connector-java-5.1.12\mysql-connector-java-5.1.12-bin.jar.
Opened the project properties in Eclipse.
Add External Jar to my Build Path and I selected mysql-connector-java-5.1.12-bin.jar.
Every time I attempt to use the servlet I get the same error regardless if I have the jar in there or if I don't. Could you help me figure this out?
As for every "3rd-party" library in flavor of a JAR file which is to be used by the webapp, just copy/drop the physical JAR file in webapp's /WEB-INF/lib. It will then be available in webapp's default classpath. Also, Eclipse is smart enough to notice that. No need to hassle with buildpath. However, make sure to remove all unnecessary references you added before, else it might collide.
An alternative is to install it in the server itself by dropping the physical JAR file in server's own /lib folder. This is required when you're using server-provided JDBC connection pool data source which in turn needs the MySQL JDBC driver.
See also:
How to add JAR libraries to WAR project without facing java.lang.ClassNotFoundException? Classpath vs Build Path vs /WEB-INF/lib
How should I connect to JDBC database / datasource in a servlet based application?
Where do I have to place the JDBC driver for Tomcat's connection pool?
JDBC CLASSPATH Not Working
Since you are running it in servlet, you need to have the jar accessible by the servlet container. You either include the connector as part of your application war or put it as part of the servlet container's extended library and datasource management stuff, if it has one. The second part is totally depend on the container that you have.
The others are right about making the driver JAR available to your servlet container. My comment was meant to suggest that you verify from the command line whether the driver itself is intact.
Rather than an empty main(), try something like this, adapted from the included documentation:
public class LoadDriver {
public static void main(String[] args) throws Exception {
Class.forName("com.mysql.jdbc.Driver");
}
}
On my platform, I'd do this:
$ ls mysql-connector-java-5.1.12-bin.jar
mysql-connector-java-5.1.12-bin.jar
$ javac LoadDriver.java
$ java -cp mysql-connector-java-5.1.12-bin.jar:. LoadDriver
On your platform, you need to use ; as the path separator, as discussed here and here.
Place mysql-connector-java-5.1.6-bin.jar to the \Apache Tomcat 6.0.18\lib folder. Your problem will be solved.
What you should not do do (especially when working on a shared project)
Ok, after had the same issue and after reading some answers here and other places. it seems that putting external lib into WEB-INF/lib is not that good idea as it pollute webapp/JRE libs with server-specific libraries - for more information check this answer"
Another solution that i do NOT recommend is: to copy it into tomcat/lib folder. although this may work, it will be hard to manage dependency for a shared(git for example) project.
Good solution 1
Create vendor folder. put there all your external lib. then, map this folder as dependency to your project. in eclipse you need to
add your folder to the build path
Project Properties -> Java build path
Libraries -> add external lib or any other solution to add your files/folder
add your build path to deployment Assembly (reference)
Project Properties -> Deployment Assembly
Add -> Java Build Path Entries
You should now see the list of libraries on your build path that you can specify for inclusion into your finished WAR.
Select the ones you want and hit Finish.
Good solution 2
Use maven (or any alternative) to manage project dependency
Just follow these steps:
1) Install eclipse
2) Import Apache to eclipse
3) Install mysql
4) Download mysqlconnector/J
5) Unzip the zipped file navigate through it until you get the bin file in it. Then place all files that are present in the folder containing bin to C:\Program Files\mysql\mysql server5.1/
then give the same path as the address while defining the driver in eclipse.
That's all very easy guys.
If the problem still persists,
Put the-
mysql-connector-java-5.0.8-bin jar in a place inside your Tomcat->lib->folder (No matter where you've installed your Tomcat). And change your environmental variable (Done by clicking Properties of Mycomputer -Advanced system settings- Environmental variables-And set a new variable name & variable values as the place where your lib file resides.Dont forget to enter a ; at the end of the path)
If still problem persists
Try downloading commons-collections-2.0.jar (http://www.docjar.com/jar_detail/commons-collections-2.0.jar.html) and paste the jar in the same place where your mysql jar resides (ie) inside Tomcat-lib.
Clean your project-Stop your server- Finally try to run.
Many times I have been facing this problem, I have experienced ClassNotFoundException.
if jar is not at physical location.
So make sure .jar file(mysql connector) in the physical location of WEB-INF lib folder. and
make sure restarting Tomcat by using shutdown command in cmd.
it should work.
The only solution worked for me is putting the .jar file under WEB-INF/lib . Hope this will help.
assuming your project is maven based, add it to your POM:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
</dependency>
Save > Build > and test connection again. It works! Your actual mysql java connector version may vary.
Put mysql-connector-java-5.1.38-bin.jar to the C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib folder.by doing this program with execute
My issue was a little different. Instead of jdbc:oracle:thin:#server:port/service i had it as server:port/service.
Missing was jdbc:oracle:thin:# in url attribute in GlobalNamingResources.Resource. But I overlooked tomcat exception's
java.sql.SQLException: Cannot create JDBC driver of class 'oracle.jdbc.driver.OracleDriver' for connect URL 'server:port/service'
for this error:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
you need to:
Import java.sql.*;
Import com.mysql.jdbc.Driver;
even if its not used till app running.