Centos mysql 连接器 java - JDBC 驱动程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22880334/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 18:38:43  来源:igfitidea点击:

Centos mysql connector java - JDBC Driver

javamysqllinuxjdbccentos

提问by arlind

I try to run this java.jar file in centos 5 and i see this error. i installed java with

我尝试在 centos 5 中运行这个 java.jar 文件,我看到了这个错误。我安装了java

yum install java 

but i think jdbc is not installed coz when i type this command

但我认为当我输入这个命令时没有安装 jdbc

yum install mysql-connector-java

i get No package mysql-connector-java available. Nothing to do

我得到没有可用的包 mysql-connector-java。没事做

when i run this commandd to start jar file

当我运行这个命令来启动 jar 文件时

java -jar "/home/httpd/5plus.net/httpdocs/test/server/ChatServer.jar"

i see this message

我看到这条消息

[root@google ~]# java -jar "/home/httpd/5plus.net/httpdocs/test/server/ChatServer.jar"


 -- Sat Apr 05 10:45:01 GMT 2014 ---   Start Main Server   ---
 -- Sat Apr 05 10:45:01 GMT 2014 ---   Can't register JDBC driver: org.gjt.mm.my        sql.Driver, Exception: java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver    ---
 -- Sat Apr 05 10:45:01 GMT 2014 ---   Port 8090 Listen Start   ---
 -- Sat Apr 05 10:45:02 GMT 2014 ---   Client Connected: Ip = 208.54.35.217   -- -
 -- Sat Apr 05 10:45:03 GMT 2014 ---   InputData From 208.54.35.217 useridx: 0 D ata:  LOGIN   ---
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/plus?user=plus&password=plus123&characterEncoding=utf8
 -- Sat Apr 05 10:45:03 GMT 2014 ---   Can't create a new connection for jdbc:my sql://localhost/plus?user=plus&password=plus123&characterEncoding=utf8   ---

回答by TMBT

You need the driver for the JDBC. The driver you appear to be using is old. If you can, you should update it to the one found here: https://dev.mysql.com/downloads/connector/j/.

您需要 JDBC 的驱动程序。您使用的驱动程序似乎很旧。如果可以,您应该将其更新为此处找到的:https: //dev.mysql.com/downloads/connector/j/

If you're doing this at the terminal, you're going to have to include the driver in the classpath. Using an IDE will make it easier. If you're using Eclipse, simply right-click your project, then select Build Path > Configure Build Path > Libraries > Add External Jars. Select the driver from your Downloads folder (or wherever you put it), and you're good to go.

如果您在终端执行此操作,则必须将驱动程序包含在类路径中。使用 IDE 会更容易。如果您使用的是 Eclipse,只需右键单击您的项目,然后选择 Build Path > Configure Build Path > Libraries > Add External Jars。从您的下载文件夹(或您放置的任何位置)中选择驱动程序,您就可以开始使用了。