未找到 SQL 驱动程序 - 但已实施驱动程序 JAR 文件
我连接到数据库:
void connectToDataBase(){
dataManager_ref = new DataBaseConfigurationManager();
try
{
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/dataBase","root","");
System.out.println("Connection successful");
}
catch (Exception e)
{
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
我为驱动程序实现了一个 JAR 文件:
mysql-connector-java-5.1.17-bin.jar
并将其导入到 servlet 中,
import java.sql.DriverManager;
这不是我第一次使用该数据库(尽管是第一次使用 Java EE Web)。这次我得到以下异常:
No suitable driver found for jdbc:mysql://localhost:3306/dataBase
应用程序正在 glassfish 服务器 3.1 上运行,我什至可以在这里使用 mysql 服务器上的数据库吗?有人可以帮忙吗,请
提前致谢, 丹尼尔
I connect to a database:
void connectToDataBase(){
dataManager_ref = new DataBaseConfigurationManager();
try
{
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/dataBase","root","");
System.out.println("Connection successful");
}
catch (Exception e)
{
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
I implemented a JAR File for the driver:
mysql-connector-java-5.1.17-bin.jar
and imported it into the servlet
import java.sql.DriverManager;
this isnt the first time I use this database (tho the first time with Java EE web). This time I get the following exception:
No suitable driver found for jdbc:mysql://localhost:3306/dataBase
The application is running on a glassfish server 3.1, can I even use a database on a mysql server here? Can somebody help please
thanks in advance,
Daniel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有时您需要显式加载 Driver 类,以便
DriverManager
能够识别它。尝试一下
在调用
DriverManager
之前You sometimes need to load the Driver class explicitly in order for the
DriverManager
to be aware of it.Try this
Before you call the
DriverManager
您可以在环境系统变量中添加CLASSPATH变量,并设置连接器的路径,路径包括connector.jar的名称。
另外 mysql-connector-java-5.1.17-bin.jar 在访问中显示出一些不兼容的情况。它给了我很多错误,所以我不得不回到 5.0.x 版本
You can add a CLASSPATH variable in Environmental System variables, and set the path to your connector, path including name of connector.jar.
Also mysql-connector-java-5.1.17-bin.jar is showing some incompatibilities in accessing. it gave me lots of errors, so i had to go bac to 5.0.x versions