找不到适合mysql的驱动程序(远程调试) [英] No suitable driver found for mysql (Remote debugging)
问题描述
我发现了一个看似常见的问题,我无法与mysql db交互.找不到合适的驱动程序不断发生. 我在这个问题上关注了大多数话题,但是我无法复制他们的解决方案,因此发布了自己的具体问题.
Hi i have found a seemingly common problem, i cant interact with a mysql db. This no suitable driver found keeps happening. I have followed most threads on this same question, however i was not able to replicate their solution so am posting my own specific question.
(大多数情况下,此线程:我无法加载JDBC驱动程序对于MySQL )
(Mostly this thread: I can't load the JDBC driver for MySQL)
我的代码:
public DBManager(){
try {
//Class.forName("com.mysql.jdbc.Driver");
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
con=DriverManager.getConnection("jdbc:mysql:3306//localhost/test","root","root");
//con=DriverManager.getConnection(c);
if(!con.isClosed()) {
con.close();
}
}
catch (SQLException e) {
e.printStackTrace();
}
现在,我读到在较新的驱动程序上,您不需要Class.forName()或registerDriver();. 我都尝试过,但仍然无法正常工作.
Now, i read that on newer drivers you dont need either Class.forName () or registerDriver(); i have tried both and i still cant get it to work.
事情正在Windows机器上开发,带有Eclipse Indigo和Connector/J 5.1.17
The thing is am developing on a windows machine, with eclipse Indigo and Connector/J 5.1.17
在具有相同连接器的远程Linux上进行部署和调试.
and deploying (and debugging) on a remote linux with the same Connector.
我是通过以下方式启动我的调试会话的:
Am launching my debug sessions with
java -Xdebug -Xrunjdwp:transport = dt_socket,address = 8998,server = y -classpath/home/dev/mysql-connector-java-5.1.17-bin.jar -jar devserver.jar
java -Xdebug -Xrunjdwp:transport=dt_socket,address=8998,server=y -classpath /home/dev/mysql-connector-java-5.1.17-bin.jar -jar devserver.jar
我得到那个例外.有帮助吗?
and i get that exception. Any help?
我来自繁重的c#开发环境,因此,如果我必须介入类路径等,请尝试逐步操作,因为我对此不太熟悉.
I come from a heavy c# development environment, so if i have to meddle with classpaths and such please try to step it by step as im not very familiar with that.
推荐答案
SQLException:没有合适的驱动程序
SQLException: no suitable driver
And indeed, your connection URL is wrong:
jdbc:mysql:3306//localhost/test
应该是:
jdbc:mysql://localhost:3306/test
另请参见 MySQL JDBC手册.
MySQL Connector/J的JDBC URL格式如下,方括号([,])中的项目是可选的:
The JDBC URL format for MySQL Connector/J is as follows, with items in square brackets ([, ]) being optional:
jdbc:mysql://[host][,failoverhost...][:port]/[database] »
[?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...
如果未指定主机名,则默认为127.0.0.1.如果未指定端口,则默认为MySQL服务器的默认端口号3306.
If the host name is not specified, it defaults to 127.0.0.1. If the port is not specified, it defaults to 3306, the default port number for MySQL servers.
jdbc:mysql://[host:port],[host:port].../[database] »
[?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...
如果未指定数据库,则将在没有默认数据库的情况下建立连接.
If the database is not specified, the connection will be made with no default database.
这篇关于找不到适合mysql的驱动程序(远程调试)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!