Java Remote Access linux server MySQL cannot connect the problem I

Source: Internet
Author: User
Tags stmt

Connection conn =NULL; String URL= "Jdbc:mysql://xxx.xx.xx.xx:3306/connection"; Try{class.forname ("Com.mysql.jdbc.Driver"); System.out.println ("Load Successfully"); String User= "Root"; String PassWord= "Root"; Conn=drivermanager.getconnection (Url,user,password);System.out.println (conn.tostring ()); Statement stmt=conn.createstatement (); String SQL= "SELECT * from Users"; ResultSet RS=stmt.executequery (SQL);  while(Rs.next ()) {System.out.println (rs.getstring (1) + "\ T" + rs.getstring (2)); }

XX in the code is the remote server IP address.

After confirming that my remote server MySQL can be connected remotely, and port 3306 can be accessed normally, it is still not possible to access through Java code.

Inadvertently add:

            if (! conn.isclosed ())            {                System.out.println ("succeeded!" );            }

Success.

Guess the reason is: because the computer has been using the MySQL, the connection is not delayed, and remote access, may be in the absence of a connection when the following code, resulting in an error.

The conn.isclosed () method should be waiting for feedback, which actually increases the time period to give the connection. ----is a complete conjecture.

Java Remote Access linux server MySQL cannot connect the problem I

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.