This question already has an answer here:
这个问题已经有了答案:
- The infamous java.sql.SQLException: No suitable driver found 8 answers
- 臭名昭著的java.sql。SQLException:没有合适的司机找到8个答案。
I am trying to create a connection to my database, when I put test my code using the main method, it works seamlessly. However, when trying to access it through Tomcat 7, it fails with error:
我正在尝试创建一个到我的数据库的连接,当我使用main方法测试我的代码时,它可以无缝地工作。但是,当试图通过Tomcat 7访问它时,它错误地失败了:
No suitable driver found for jdbc:mysql://localhost/dbname.
I am using pooling. I put in mysql connector (5.1.15), dbcp (1.4) , and pool(1.4.5) libraries in WEB-INF/lib and in .classpath as well. I am using Eclipse IDE. My code for the database driver is:
我用池。我将mysql连接器(5.1.15)、dbcp(1.4)和pool(1.4.5)库放在WEB-INF/lib和.classpath中。我使用的是Eclipse IDE。我的数据库驱动程序的代码是:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.apache.tomcat.dbcp.dbcp.ConnectionFactory;
import org.apache.tomcat.dbcp.dbcp.DriverManagerConnectionFactory;
import org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory;
import org.apache.tomcat.dbcp.dbcp.PoolingDriver;
import org.apache.tomcat.dbcp.pool.impl.GenericObjectPool;
public class DatabaseConnector {
public static String DB_URI = "jdbc:mysql://localhost/dbname";
public static String DB_USER = "test";
public static String DB_PASS = "password";
// Singleton instance
protected static DatabaseConnector _instance;
protected String _uri;
protected String _username;
protected String _password;
/**
* Singleton, so no public constructor
*/
protected DatabaseConnector(String uri, String username, String password) {
_uri = uri;
_username = username;
_password = password;
GenericObjectPool connectionPool = new GenericObjectPool(null);
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
_uri, _username, _password);
PoolableConnectionFactory poolableConnectionFactory =
new PoolableConnectionFactory(connectionFactory, connectionPool,
null, null, false, true);
PoolingDriver driver = new PoolingDriver();
driver.registerPool("test", connectionPool);
}
/**
* Returns the singleton instance
*/
public static DatabaseConnector getInstance() {
if (_instance == null) {
_instance = new DatabaseConnector(DB_URI, DB_USER, DB_PASS);
}
return _instance;
}
/**
* Returns a connection to the database
*/
public Connection getConnection() {
Connection con = null;
try {
con = DriverManager.getConnection("jdbc:apache:commons:dbcp:test");
} catch (SQLException e) {
throw new RuntimeException(e);
}
return con;
}
}
Start of my stack trace:
堆栈跟踪的开始:
Apr 5, 2011 9:49:14 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Login] in context with path [/Project]
threw exception
java.lang.RuntimeException: java.sql.SQLException:
No suitable driver found for jdbc:mysql://localhost/dbname
What is causing this error?
是什么导致了这个错误?
21 个解决方案
#1
49
Try putting the driver jar in the server lib folder. ($CATALINA_HOME/lib)
尝试将驱动程序jar放到服务器lib文件夹中。($ CATALINA_HOME / lib)
I believe that the connection pool needs to be set up even before the application is instantiated. (At least that's how it works in Jboss)
我认为在实例化应用程序之前,需要设置连接池。(至少在Jboss中是这样的)
#2
39
The reason you got this error:
你得到这个错误的原因是:
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/dbname
Is because you forgot to register your mysql jdbc driver with the java application.
因为您忘记了用java应用程序注册mysql jdbc驱动程序。
This is what you wrote:
这是你写的:
Connection con = null;
try {
con = DriverManager.getConnection("jdbc:apache:commons:dbcp:test");
} catch (SQLException e) {
throw new RuntimeException(e);
}
Should be this:
应该是这样的:
Connection con = null;
try {
//registering the jdbc driver here, your string to use
//here depends on what driver you are using.
Class.forName("something.jdbc.driver.YourFubarDriver");
con = DriverManager.getConnection("jdbc:apache:commons:dbcp:test");
} catch (SQLException e) {
throw new RuntimeException(e);
}
You'll have to read the manual on your specific mysql jdbc driver to find the exact string to place inside the the Class.forName("...") parameter.
您必须阅读特定的mysql jdbc驱动程序的手册,才能在类. forname(“…”)参数中找到正确的字符串。
Class.forName not required with JDBC v.4
类。不需要使用JDBC .4。
Starting with Java 6, Class.forName("something.jdbc.driver.YourFubarDriver")
is not necessary anymore if you use a recent (JDBC v.4) driver. For details read this: http://onjava.com/pub/a/onjava/2006/08/02/jjdbc-4-enhancements-in-java-se-6.html
如果您使用的是最近的(JDBC v.4)驱动程序,那么从Java 6开始,Class.forName(“something.jdbc.driver.YourFubarDriver”)就不再需要了。有关详细信息,请参阅:http://onjava.com/pub/a/onjava/2006/08/02/jjdbc-4-enhancements-in-java-se-6.html。
#3
31
I had the same problem using Tomcat7 with mysql-connector-java-5.1.26 that I put in both my $CATALINA_HOME/lib and WEB-INF/lib, just in case. But it wouldn't find it until I used either one of these two statements before getting the connection:
我使用Tomcat7和mysql- connecter -java-5.1.26也有同样的问题,我把我的$CATALINA_HOME/lib和WEB-INF/lib放在一起,以防万一。但在我使用这两种表述之前,它是找不到的:
DriverManager.registerDriver(new com.mysql.jdbc.Driver ());
DriverManager。registerDriver(新com.mysql.jdbc。司机());
OR
或
Class.forName("com.mysql.jdbc.Driver");
forname(“com.mysql.jdbc.Driver”);
I then followed up with removing mysql-connector-java-5.1.26 from $CATALINA_HOME/lib and the connection still works.
然后,我从$CATALINA_HOME/lib中删除了mysql-connector-java-5.1.26,并且连接仍然有效。
#4
8
When running tomcat out of eclipse it won't pick the lib set in CATALINA_HOME/lib
, there are two ways to fix it. Double click on Tomcat server in eclipse servers view, it will open the tomcat plugin config, then either:
当在eclipse中运行tomcat时,它不会选择CATALINA_HOME/lib中的lib,有两种方法可以修复它。在eclipse servers视图中双击Tomcat服务器,它将打开Tomcat插件配置,然后:
- Click on "Open Launch Config" > Classpath tab set the mysql connector/j jar location. or
- 单击“打开启动配置”>类路径选项卡设置mysql连接器/j jar位置。或
- Server Location > select option which says "Use Tomcat installation (take control of Tomcat installation)"
- 服务器位置> select选项,该选项表示“使用Tomcat安装(控制Tomcat安装)”
#5
4
I had the mysql jdbc library in both $CATALINA_HOME/lib and WEB-INF/lib, still i got this error . I needed Class.forName("com.mysql.jdbc.Driver"); to make it work.
我在两个$CATALINA_HOME/lib和WEB-INF/lib中都有mysql jdbc库,但是仍然有这个错误。我需要forname(“com.mysql.jdbc.Driver”);从而使其工作。
#6
3
I had the same problem, all you need to do is define classpath environment variable for tomcat, you can do it by adding a file, in my case C:\apache-tomcat-7.0.30\bin\setenv.bat
, containing:
我有同样的问题,您所需要做的就是为tomcat定义classpath环境变量,您可以在我的案例C:\apache-tomcat-7.0.30\bin\setenv中添加一个文件。蝙蝠,包含:
set "CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\lib\mysql-connector-java-5.1.14-bin.jar"
then code, in my case:
然后代码,在我的例子中:
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/database_name", "root", "");
works fine.
工作很好。
#7
2
I'm running Tomcat 7 in Eclipse with Java 7 and using the jdbc driver for MSSQL sqljdbc4.jar.
我使用Java 7在Eclipse中运行Tomcat 7,并在MSSQL sqljdbc4.jar中使用jdbc驱动程序。
When running the code outside of tomcat, from a standalone java app, this worked just fine:
当运行tomcat之外的代码时,从一个独立的java应用程序中,这样做很好:
connection = DriverManager.getConnection(conString, user, pw);
However, when I tried to run the same code inside of Tomcat 7, I found that I could only get it work by first registering the driver, changing the above to this:
但是,当我尝试在Tomcat 7中运行相同的代码时,我发现我只能通过首先注册驱动程序来获得它,将上面的代码更改为:
DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());
connection = DriverManager.getConnection(conString, user, pw);
#8
2
Use:
使用:
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Registro exitoso");
} catch (Exception e) {
System.out.println(e.toString());
}
DriverManager.getConnection(..
#9
2
Bro, you can also write code as below:
兄弟,你也可以写代码如下:
import java.sql.*;
import java.io.*;
public class InsertDatabase {
public static void main(String[] args) {
// TODO Auto-generated method stub
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/Maulik","root","root");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from Employee");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
#10
1
if you are using netbeans you must add Mysql JDBC driver in the library list of the project, in the properties of your project
如果使用netbeans,必须在项目的库列表中添加Mysql JDBC驱动程序,在项目的属性中。
#11
1
I also had the same problem some time before, but I solved that issue.
我以前也有过同样的问题,但是我解决了这个问题。
There may be different reasons for this exception. And one of them may be that the jar you are adding to your lib folder may be old.
这个例外可能有不同的原因。其中一个可能是你添加到lib文件夹的jar可能是旧的。
Try to find out the latest mysql-connector-jar version and add that to your classpath. It may solve your issue. Mine was solved like that.
尝试找到最新的mysql-connector-jar版本,并将其添加到类路径中。它可以解决你的问题。我的是这样解决的。
#12
1
Most of time it happen because two mysql-connector-java-3.0.14-production-bin.jar file. One in lib folder of tomcat and another in classpath of the project.
大多数情况下,这是因为两个mysql- connecter -java-3.0.14- productionbin。jar文件。一个在tomcat的lib文件夹中,另一个在项目的类路径中。
Just try to remove mysql-connector-java-3.0.14-production-bin.jar from lib folder.
尝试删除mysql-connector-java-3.0.14- productionbin。jar从lib文件夹。
This way it is working for me.
这种方式对我很有效。
#13
1
From what i have observed there might be two reasons for this Exception to occur: (1)Your Driver name is not spelled Correctly. (2)Driver hasn't been Associated Properly with the Java Project Steps to follow in Eclipse: (1)Create a new Java Project. (2)copy The connector Jar file (3)Right Click on the Java project and paste it there. (4)Right click on the Java project -> Properties ->Java Build Path - >libraries-> Add Jar ->choose ur project(select the jar file from dropdown) and click ok.
从我观察到的情况来看,可能有两个原因导致了这个异常:(1)您的驱动程序名称没有拼写正确。(2)驱动程序没有与Eclipse中遵循的Java项目步骤相关联:(1)创建一个新的Java项目。(2)复制连接器Jar文件(3)右键单击Java项目并粘贴到那里。(4)右键单击Java项目->属性->Java构建路径->库->添加Jar ->选择ur项目(从下拉菜单中选择Jar文件)并点击ok。
#14
1
add the artifact from maven.
从maven中添加工件。
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
#15
1
The solution is straightforward.
解决方案是简单。
Make sure that the database connector can be reached by your classpath when running (not compiling) the program, e.g.:
当运行(不编译)程序时,请确保您的类路径可以访问数据库连接器。
java -classpath .;c:\path\to\mysql-connector-java-5.1.39.jar YourMainClass
Also, if you're using an old version of Java (pre JDBC 4.0), before you do DriverManager.getConnection
this line is required:
此外,如果您使用的是旧版本的Java (pre - JDBC 4.0),那么在您进行驱动管理之前。这条线是需要的:
Class.forName("your.jdbc.driver.TheDriver"); // this line is not needed for modern Java
#16
0
When developing using Ubuntu (Xubuntu 12.04.1) I 'HAD' to do the following:
在使用Ubuntu (Xubuntu 12.04.1)时,我需要做以下工作:
Using
使用
Eclipse Juno (downloaded, not installed via the software centre), Tomcat 7 (downloaded in a custom user directory) also added as a Server in Eclipse, Dynamic Web Project with a 3.0 Servlet, MySQL Server on localhost configured and tested with user and password (make sure to test) MySQL connector driver 5.1.24 jar,
Eclipse朱诺(下载,而不是通过软件中心安装),Tomcat 7(在一个定制的用户目录下载)也添加一个服务器在Eclipse中,动态Web项目3.0 Servlet,MySQL服务器在本地主机配置和测试用户名和密码(确保测试)MySQL连接器司机5.1.24罐,
I 'HAD', and I repeat 'HAD', to us the Class.Load("com.mysql.jdbc.Driver") statement along with adding the connector driver.jar to be in the web project lib folder for it to work in this situation.
我“有”,然后重复“HAD”,给我们的Class.Load(“com.mysql.jdbc.Driver”)语句以及添加连接器驱动程序。jar位于web项目lib文件夹中,以便它在这种情况下工作。
IMPORTANT!!: after you copy the driver.jar to the lib make sure you refresh your project in Eclipse before running the servlet via Tomcat.
重要! !在你复制了驱动程序之后。jar到lib,确保在运行servlet通过Tomcat之前,在Eclipse中刷新项目。
I did try adding the connector driver jar file via the Build Path with and without ClassLoad but it did not work!
我确实尝试了通过构建路径添加连接器驱动程序jar文件,但它不起作用!
Hope this helps anyone starting development with this specific situation: the Java community provides a 'LOT' of documentation but there are so many variables its hard to cover all of them and it makes things very hard on the new guy.
希望这能帮助任何人在这个特定的情况下开始开发:Java社区提供了大量的文档,但是有太多的变量难以覆盖所有的文档,这使得新成员的工作变得非常困难。
I think if someone could explain why Class.Load is required here (in this situation) it would be beneficial.
我想如果有人能解释为什么上课。这里需要负载(在这种情况下)是有益的。
Enjoy
享受
#17
0
Since no one gave this answer, I would also like to add that, you can just add the jdbc driver file(mysql-connector-java-5.1.27-bin.jar
in my case) to the lib folder of your server(Tomcat in my case). Restart the server and it should work.
由于没有人给出这个答案,所以我还想添加这个,您可以添加jdbc驱动程序文件(mysql-connector-java-5.1.27-bin)。jar在我的情况下)到您的服务器的lib文件夹(在我的例子中是Tomcat)。重新启动服务器,它应该工作。
#18
0
-
Put mysql-connector-java-5.0.8-bin.jar in $CATALINA_HOME/lib
把mysql-connector-java-5.0.8-bin。jar CATALINA_HOME美元/ lib
-
Check for typo in connection url, example
"jdbc:mysql://localhost:3306/report" ('report' here is the db name)检查连接url中的typo,例如“jdbc:mysql://localhost:3306/报告”(这里的“报告”是db名称)
- Make sure to use machine name(example : localhost instead of ip address(127.0.0.1))
- 确保使用机器名称(例如:localhost而不是ip地址(127.0.0.1))
#19
0
Add the driver class to the bootstrapclasspath. The problem is in java.sql.DriverManager that doesn't see the drivers loaded by ClassLoaders other than bootstrap ClassLoader.
将驱动类添加到bootstrapclasspath。问题在于java.sql。驱动程序管理器没有看到由类加载器加载的驱动程序,而不是引导类加载器。
#20
0
From other * thread:
从其他*线程:
"Second. Make sure that you have MySQL JDBC Driver aka Connector/J in JMeter's classpath. If you don't - download it, unpack and drop mysql-connector-java-x.xx.xx-bin.jar to JMeter's /lib folder. JMeter restart will be required to pick the library up"
“第二。确保在JMeter的类路径中有MySQL JDBC驱动程序aka Connector/J。如果您不下载它,请打开并删除mysql-connector-java-x.xx.xx-bin。jar到JMeter的/lib文件夹。需要重新启动JMeter来选择库
Please be sure that .jar file is added directly to the lib folder.
请确保.jar文件直接添加到lib文件夹。
#21
-2
You can stick the jar in the path of run time of jboss like this:
您可以在jboss运行时的路径中插入这个jar:
C:\User\user\workspace\jboss-as-web-7.0.0.Final\standalone\deployments\MYapplicationEAR.ear\test.war\WEB-INF\lib ca marche 100%
C:\ \用户\ workspace \ jboss-as-web-7.0.0.Final \独立\ \ MYapplicationEAR.ear \测试部署。战争\ web - inf \ lib ca马尔凯100%
#1
49
Try putting the driver jar in the server lib folder. ($CATALINA_HOME/lib)
尝试将驱动程序jar放到服务器lib文件夹中。($ CATALINA_HOME / lib)
I believe that the connection pool needs to be set up even before the application is instantiated. (At least that's how it works in Jboss)
我认为在实例化应用程序之前,需要设置连接池。(至少在Jboss中是这样的)
#2
39
The reason you got this error:
你得到这个错误的原因是:
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/dbname
Is because you forgot to register your mysql jdbc driver with the java application.
因为您忘记了用java应用程序注册mysql jdbc驱动程序。
This is what you wrote:
这是你写的:
Connection con = null;
try {
con = DriverManager.getConnection("jdbc:apache:commons:dbcp:test");
} catch (SQLException e) {
throw new RuntimeException(e);
}
Should be this:
应该是这样的:
Connection con = null;
try {
//registering the jdbc driver here, your string to use
//here depends on what driver you are using.
Class.forName("something.jdbc.driver.YourFubarDriver");
con = DriverManager.getConnection("jdbc:apache:commons:dbcp:test");
} catch (SQLException e) {
throw new RuntimeException(e);
}
You'll have to read the manual on your specific mysql jdbc driver to find the exact string to place inside the the Class.forName("...") parameter.
您必须阅读特定的mysql jdbc驱动程序的手册,才能在类. forname(“…”)参数中找到正确的字符串。
Class.forName not required with JDBC v.4
类。不需要使用JDBC .4。
Starting with Java 6, Class.forName("something.jdbc.driver.YourFubarDriver")
is not necessary anymore if you use a recent (JDBC v.4) driver. For details read this: http://onjava.com/pub/a/onjava/2006/08/02/jjdbc-4-enhancements-in-java-se-6.html
如果您使用的是最近的(JDBC v.4)驱动程序,那么从Java 6开始,Class.forName(“something.jdbc.driver.YourFubarDriver”)就不再需要了。有关详细信息,请参阅:http://onjava.com/pub/a/onjava/2006/08/02/jjdbc-4-enhancements-in-java-se-6.html。
#3
31
I had the same problem using Tomcat7 with mysql-connector-java-5.1.26 that I put in both my $CATALINA_HOME/lib and WEB-INF/lib, just in case. But it wouldn't find it until I used either one of these two statements before getting the connection:
我使用Tomcat7和mysql- connecter -java-5.1.26也有同样的问题,我把我的$CATALINA_HOME/lib和WEB-INF/lib放在一起,以防万一。但在我使用这两种表述之前,它是找不到的:
DriverManager.registerDriver(new com.mysql.jdbc.Driver ());
DriverManager。registerDriver(新com.mysql.jdbc。司机());
OR
或
Class.forName("com.mysql.jdbc.Driver");
forname(“com.mysql.jdbc.Driver”);
I then followed up with removing mysql-connector-java-5.1.26 from $CATALINA_HOME/lib and the connection still works.
然后,我从$CATALINA_HOME/lib中删除了mysql-connector-java-5.1.26,并且连接仍然有效。
#4
8
When running tomcat out of eclipse it won't pick the lib set in CATALINA_HOME/lib
, there are two ways to fix it. Double click on Tomcat server in eclipse servers view, it will open the tomcat plugin config, then either:
当在eclipse中运行tomcat时,它不会选择CATALINA_HOME/lib中的lib,有两种方法可以修复它。在eclipse servers视图中双击Tomcat服务器,它将打开Tomcat插件配置,然后:
- Click on "Open Launch Config" > Classpath tab set the mysql connector/j jar location. or
- 单击“打开启动配置”>类路径选项卡设置mysql连接器/j jar位置。或
- Server Location > select option which says "Use Tomcat installation (take control of Tomcat installation)"
- 服务器位置> select选项,该选项表示“使用Tomcat安装(控制Tomcat安装)”
#5
4
I had the mysql jdbc library in both $CATALINA_HOME/lib and WEB-INF/lib, still i got this error . I needed Class.forName("com.mysql.jdbc.Driver"); to make it work.
我在两个$CATALINA_HOME/lib和WEB-INF/lib中都有mysql jdbc库,但是仍然有这个错误。我需要forname(“com.mysql.jdbc.Driver”);从而使其工作。
#6
3
I had the same problem, all you need to do is define classpath environment variable for tomcat, you can do it by adding a file, in my case C:\apache-tomcat-7.0.30\bin\setenv.bat
, containing:
我有同样的问题,您所需要做的就是为tomcat定义classpath环境变量,您可以在我的案例C:\apache-tomcat-7.0.30\bin\setenv中添加一个文件。蝙蝠,包含:
set "CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\lib\mysql-connector-java-5.1.14-bin.jar"
then code, in my case:
然后代码,在我的例子中:
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/database_name", "root", "");
works fine.
工作很好。
#7
2
I'm running Tomcat 7 in Eclipse with Java 7 and using the jdbc driver for MSSQL sqljdbc4.jar.
我使用Java 7在Eclipse中运行Tomcat 7,并在MSSQL sqljdbc4.jar中使用jdbc驱动程序。
When running the code outside of tomcat, from a standalone java app, this worked just fine:
当运行tomcat之外的代码时,从一个独立的java应用程序中,这样做很好:
connection = DriverManager.getConnection(conString, user, pw);
However, when I tried to run the same code inside of Tomcat 7, I found that I could only get it work by first registering the driver, changing the above to this:
但是,当我尝试在Tomcat 7中运行相同的代码时,我发现我只能通过首先注册驱动程序来获得它,将上面的代码更改为:
DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());
connection = DriverManager.getConnection(conString, user, pw);
#8
2
Use:
使用:
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Registro exitoso");
} catch (Exception e) {
System.out.println(e.toString());
}
DriverManager.getConnection(..
#9
2
Bro, you can also write code as below:
兄弟,你也可以写代码如下:
import java.sql.*;
import java.io.*;
public class InsertDatabase {
public static void main(String[] args) {
// TODO Auto-generated method stub
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/Maulik","root","root");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from Employee");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
#10
1
if you are using netbeans you must add Mysql JDBC driver in the library list of the project, in the properties of your project
如果使用netbeans,必须在项目的库列表中添加Mysql JDBC驱动程序,在项目的属性中。
#11
1
I also had the same problem some time before, but I solved that issue.
我以前也有过同样的问题,但是我解决了这个问题。
There may be different reasons for this exception. And one of them may be that the jar you are adding to your lib folder may be old.
这个例外可能有不同的原因。其中一个可能是你添加到lib文件夹的jar可能是旧的。
Try to find out the latest mysql-connector-jar version and add that to your classpath. It may solve your issue. Mine was solved like that.
尝试找到最新的mysql-connector-jar版本,并将其添加到类路径中。它可以解决你的问题。我的是这样解决的。
#12
1
Most of time it happen because two mysql-connector-java-3.0.14-production-bin.jar file. One in lib folder of tomcat and another in classpath of the project.
大多数情况下,这是因为两个mysql- connecter -java-3.0.14- productionbin。jar文件。一个在tomcat的lib文件夹中,另一个在项目的类路径中。
Just try to remove mysql-connector-java-3.0.14-production-bin.jar from lib folder.
尝试删除mysql-connector-java-3.0.14- productionbin。jar从lib文件夹。
This way it is working for me.
这种方式对我很有效。
#13
1
From what i have observed there might be two reasons for this Exception to occur: (1)Your Driver name is not spelled Correctly. (2)Driver hasn't been Associated Properly with the Java Project Steps to follow in Eclipse: (1)Create a new Java Project. (2)copy The connector Jar file (3)Right Click on the Java project and paste it there. (4)Right click on the Java project -> Properties ->Java Build Path - >libraries-> Add Jar ->choose ur project(select the jar file from dropdown) and click ok.
从我观察到的情况来看,可能有两个原因导致了这个异常:(1)您的驱动程序名称没有拼写正确。(2)驱动程序没有与Eclipse中遵循的Java项目步骤相关联:(1)创建一个新的Java项目。(2)复制连接器Jar文件(3)右键单击Java项目并粘贴到那里。(4)右键单击Java项目->属性->Java构建路径->库->添加Jar ->选择ur项目(从下拉菜单中选择Jar文件)并点击ok。
#14
1
add the artifact from maven.
从maven中添加工件。
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
#15
1
The solution is straightforward.
解决方案是简单。
Make sure that the database connector can be reached by your classpath when running (not compiling) the program, e.g.:
当运行(不编译)程序时,请确保您的类路径可以访问数据库连接器。
java -classpath .;c:\path\to\mysql-connector-java-5.1.39.jar YourMainClass
Also, if you're using an old version of Java (pre JDBC 4.0), before you do DriverManager.getConnection
this line is required:
此外,如果您使用的是旧版本的Java (pre - JDBC 4.0),那么在您进行驱动管理之前。这条线是需要的:
Class.forName("your.jdbc.driver.TheDriver"); // this line is not needed for modern Java
#16
0
When developing using Ubuntu (Xubuntu 12.04.1) I 'HAD' to do the following:
在使用Ubuntu (Xubuntu 12.04.1)时,我需要做以下工作:
Using
使用
Eclipse Juno (downloaded, not installed via the software centre), Tomcat 7 (downloaded in a custom user directory) also added as a Server in Eclipse, Dynamic Web Project with a 3.0 Servlet, MySQL Server on localhost configured and tested with user and password (make sure to test) MySQL connector driver 5.1.24 jar,
Eclipse朱诺(下载,而不是通过软件中心安装),Tomcat 7(在一个定制的用户目录下载)也添加一个服务器在Eclipse中,动态Web项目3.0 Servlet,MySQL服务器在本地主机配置和测试用户名和密码(确保测试)MySQL连接器司机5.1.24罐,
I 'HAD', and I repeat 'HAD', to us the Class.Load("com.mysql.jdbc.Driver") statement along with adding the connector driver.jar to be in the web project lib folder for it to work in this situation.
我“有”,然后重复“HAD”,给我们的Class.Load(“com.mysql.jdbc.Driver”)语句以及添加连接器驱动程序。jar位于web项目lib文件夹中,以便它在这种情况下工作。
IMPORTANT!!: after you copy the driver.jar to the lib make sure you refresh your project in Eclipse before running the servlet via Tomcat.
重要! !在你复制了驱动程序之后。jar到lib,确保在运行servlet通过Tomcat之前,在Eclipse中刷新项目。
I did try adding the connector driver jar file via the Build Path with and without ClassLoad but it did not work!
我确实尝试了通过构建路径添加连接器驱动程序jar文件,但它不起作用!
Hope this helps anyone starting development with this specific situation: the Java community provides a 'LOT' of documentation but there are so many variables its hard to cover all of them and it makes things very hard on the new guy.
希望这能帮助任何人在这个特定的情况下开始开发:Java社区提供了大量的文档,但是有太多的变量难以覆盖所有的文档,这使得新成员的工作变得非常困难。
I think if someone could explain why Class.Load is required here (in this situation) it would be beneficial.
我想如果有人能解释为什么上课。这里需要负载(在这种情况下)是有益的。
Enjoy
享受
#17
0
Since no one gave this answer, I would also like to add that, you can just add the jdbc driver file(mysql-connector-java-5.1.27-bin.jar
in my case) to the lib folder of your server(Tomcat in my case). Restart the server and it should work.
由于没有人给出这个答案,所以我还想添加这个,您可以添加jdbc驱动程序文件(mysql-connector-java-5.1.27-bin)。jar在我的情况下)到您的服务器的lib文件夹(在我的例子中是Tomcat)。重新启动服务器,它应该工作。
#18
0
-
Put mysql-connector-java-5.0.8-bin.jar in $CATALINA_HOME/lib
把mysql-connector-java-5.0.8-bin。jar CATALINA_HOME美元/ lib
-
Check for typo in connection url, example
"jdbc:mysql://localhost:3306/report" ('report' here is the db name)检查连接url中的typo,例如“jdbc:mysql://localhost:3306/报告”(这里的“报告”是db名称)
- Make sure to use machine name(example : localhost instead of ip address(127.0.0.1))
- 确保使用机器名称(例如:localhost而不是ip地址(127.0.0.1))
#19
0
Add the driver class to the bootstrapclasspath. The problem is in java.sql.DriverManager that doesn't see the drivers loaded by ClassLoaders other than bootstrap ClassLoader.
将驱动类添加到bootstrapclasspath。问题在于java.sql。驱动程序管理器没有看到由类加载器加载的驱动程序,而不是引导类加载器。
#20
0
From other * thread:
从其他*线程:
"Second. Make sure that you have MySQL JDBC Driver aka Connector/J in JMeter's classpath. If you don't - download it, unpack and drop mysql-connector-java-x.xx.xx-bin.jar to JMeter's /lib folder. JMeter restart will be required to pick the library up"
“第二。确保在JMeter的类路径中有MySQL JDBC驱动程序aka Connector/J。如果您不下载它,请打开并删除mysql-connector-java-x.xx.xx-bin。jar到JMeter的/lib文件夹。需要重新启动JMeter来选择库
Please be sure that .jar file is added directly to the lib folder.
请确保.jar文件直接添加到lib文件夹。
#21
-2
You can stick the jar in the path of run time of jboss like this:
您可以在jboss运行时的路径中插入这个jar:
C:\User\user\workspace\jboss-as-web-7.0.0.Final\standalone\deployments\MYapplicationEAR.ear\test.war\WEB-INF\lib ca marche 100%
C:\ \用户\ workspace \ jboss-as-web-7.0.0.Final \独立\ \ MYapplicationEAR.ear \测试部署。战争\ web - inf \ lib ca马尔凯100%