国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

JDBC ? MySQL? ?? "?? ?? ??" ??
P粉038161873
P粉038161873 2023-08-24 15:46:59
0
1
626
<p>我正在嘗試連接到本地 MySQL 服務(wù)器,但不斷收到錯(cuò)誤消息。</p> <p>這是代碼。</p> <pre class="brush:php;toolbar:false;">public class Connect { public static void main(String[] args) { Connection conn = null; try { String userName = "myUsername"; String password = "myPassword"; String url = "jdbc:mysql://localhost:3306/myDatabaseName"; Class.forName("com.mysql.jdbc.Driver").newInstance(); conn = DriverManager.getConnection(url, userName, password); System.out.println("Database connection established"); } catch (Exception e) { System.err.println("Cannot connect to database server"); System.err.println(e.getMessage()); e.printStackTrace(); } finally { if (conn != null) { try { conn.close(); System.out.println("Database Connection Terminated"); } catch (Exception e) {} } } } }</pre> <p>以及錯(cuò)誤:</p> <pre class="brush:php;toolbar:false;">Cannot connect to database server 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. 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(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116) at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:344) at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2333) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2370) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2154) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:185) at Connect.main(Connect.java:16) Caused by: java.net.ConnectException: Connection refused at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) at java.net.Socket.connect(Socket.java:529) at java.net.Socket.connect(Socket.java:478) at java.net.Socket.<init>(Socket.java:375) at java.net.Socket.<init>(Socket.java:218) at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:257) at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:294) ... 15 more</pre> <p>我已經(jīng)設(shè)置了類路徑,確保 my.cnf 已注釋掉跳過網(wǎng)絡(luò)選項(xiàng)。 </p> <p>java版本是1.2.0_26(64位) mysql 5.5.14 mysql連接器5.1.17</p> <p>我確保用戶有權(quán)訪問我的數(shù)據(jù)庫。</p>
P粉038161873
P粉038161873

?? ??(1)
P粉068486220

?? ? ?????? ?? ??? ?????. ? ??? ??? ????:

???

? ??? ???? ? ??? ?????. ?? ????? ??? ?? ?? ??? ?????? ? ? ?? ?? ???? ?????. ??? ??? ???? ??? ??????. ??? ??? ???? ??? ??? ?????.

????? ? ??? ?? ???? ??? ??? ? ????? ??? ?? ?? ???? ???? ?? ???? ???? ??? ??? ?????!

?> ? ??? ???? ??? ? ?? ?????? ?? ? ??? ?? ??? ??? ?? ? ???? ? ????. ??? ??? ??? ?? ????? ??????? ?? ??? ?? ?? ??? ? ????.

??? ?? ?? ??? ??? ????? ???? ???!

??? ?? ????? ?? ??????. ? ???? ?? ??? ? ??? ??? ?? ????? ???????.

?: MySQL ?? ??? ??? ???? ?? ?? ??? ?????.

  • Linux: /etc/mysql/my.cnf/etc/my.cnf (Linux ???? ??? MySQL ???? ?? ??) p>

  • Windows: C:**ProgramData**MySQLMySQL Server 5.6my.ini(???? ??? ??? ProgramData?? ?? ?????)

???? ??? ????.

  • ?? bind-address??:

    bind-address ??? ?? ??? ????? ?? IP ? ??? ?????.

    ???

    ??

    ???
  • “???? ????”? ?? ?????

    MySQL ?? ??? skip-networking 行,請(qǐng)?jiān)谠撔械拈_頭添加 # ??? ??? ?? ?????.

  • "wait_timeout" ? "interactive_timeout" ??

    MySQL ?? ??? ?? ?? ?????:

    ???
  • Java? "localhost"? [127.0.0.1] ?? [:::1]? ???? ??? ?????

    MySQL? ??? ? ?? ??? 127.0.0.1 (IPv4),但不能識(shí)別 :::1 (IPv6)

    ?? ? ?? ?? ? ??? ???? ? ??? ?? ? ????.

    1. ?? ???? 127.0.0.1 而不是 localhost 以避免 localhost 被轉(zhuǎn)換為 ::: 1

      ??
    2. ?? -Djava.net.preferIPv4Stack=true運(yùn)行java以強(qiáng)制java使用IPv4而不是IPv6。在 Linux 上,這也可以通過運(yùn)行(或?qū)⑵浞湃?/etc/profile? ???? ??? ?????.

      ???
  • ?? ?? ??? ??, ??? ? ???? ?? ???? ??

    MySQL ???? ????? ???? ?? ?????? ?? ???? ???? ?????.

    Linux?? iptables? ????? ?????. iptables? ?? ??? ?? tcp ??? mysql ??? ???? ?? ????? tcp ??? ??? ??? ???? ?? ??? ? ????.

    ???

    Windows?? ???? ?? ?????? ?????.

  • ?? ??? ??

    ?? ???? ?????. ?? ???? ??? ??? ???.

    ???

???? ??? ??? ?????. ?? ?? ???? ?? ?? ?? ????? ???.

"localhost"? ??? ?? 127.0.0.1? ?????. ?? ??? ?? ?? ???? ?? ??? ??? ???.

???

????? MySQL? ?? ??? 3306???.

??? ??? ????? MySQL ??? ??? ??? ????? ???? ?? ?? ???.

  • JDK ???? ????? ?? ????
  • ??? JDK ? JRE ???(?: JDK 6 ? 7)
  • max_allowed_packet
  • ? ???? ???.

"max_allowed_packet"? ?? ?? ?? ?? ?? ?? ??? ???? MySQL ?? ??? ?????. ??? ?? ? ??? ???? ? ??? ?? ????.

  • Tomcat ?? ??

TOMCAT6_SECURITY=yes? TOMCAT6_SECURITY=no? ?????

  • validationQuery ?? ??

?? ??? ?? ??? ????? ??? ??="select now()"? ?????

  • ?? ???

?? ???? ?? ??? ?????:

???

??? ??? ? ?? ?? ??? ??? ?? ???? ??? ?? ?? ????. ?? ???? ??? ??? ???? ??? ???? ?????.

??? ? ??? ??? ???????

? ??? ??????? SELECT? ?? ??? ????. ??? ?? ?? ?? ???. ?? ??? ??? ???? ?? ??? ???? ? ??? ?????. ?? ? ?? ?? ??? ?? ???? ?? ??(?? ???) ??? ???? ????? ????? ??????. ??? ? ??? ??? ???. ??? ? ??? ???? ??? ???? ???????.

#??# ? ??? ???? ???? ??? ??? ????. ??? ??? ?? ?? ?? ??? ???? ?? ????. ???? ?? ? ? ??? ???? ??????? ?? ??? ? ?? ?? ?? ???? ??? ?? ? ????. ??? ??????? ????? ?? ??? ? ? ??? ???? ?? ?? ??? ?? ? ???? "wait_timeout" ? ?? MySQL ??? ????? ??? ?? ???? ?? ?? ??? ?? ????.