错误展示:程序运行完后,出现这么一大堆,其实你不应该点项目右键运行,而是,点开项目的主类,右键运行就可以了,如果你的代码没问题,就OK了
<ConnectionProperties>
<PropertyCategory name="Connection/Authentication">
<Property name="user" required="No" default="" sortOrder="-2147483647" since="all versions">
The user to connect as
</Property>
<Property name="password" required="No" default="" sortOrder="-2147483646" since="all versions">
The password to use when connecting
</Property>
~~~~~~~~~~
~~~~~~~~~~~
错误展示:实例中String url="jdbc:mysql://host:3306/my?user=root&password=mysqladmin";用的是蓝色的host,而我自己用的localhost,替换了蓝色host就可以了,哈哈,终于解决了控绕我1个星期的问题了,呵呵。
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1121)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:357)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2482)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2519)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2304)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:346)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at JDBCExample.main(JDBCExample.java:11)
Caused by: java.net.UnknownHostException: host
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(Unknown Source)
at java.net.InetAddress.getAddressesFromNameService(Unknown Source)
at java.net.InetAddress.getAllByName0(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:249)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:307)
... 15 more
import java.sql.DriverManager;
import java.sql.Connection;String url="jdbc:mysql://localhost:3306/my?user=root&password=mysqladmin";
//注释解释,这是最为关键的,在建mysql时设置为了localhost,你要看自己设置的是什么,my是建的数据库的名字,
Connection conn=DriverManager.getConnection(url);