一段时间以来,我的Java应用程序一直存在问题。为了弄清楚从新驱动程序到注册驱动程序到更改MySQL数据库权限,我尝试了几种方法。我只有在连接外部IP时才会遇到此问题。我认为这可能与IPV6有关,但是我试图在树莓派上禁用它,但是当我运行“ netstat -tlnp”时,我得到了:
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:8005 0.0.0.0:* LISTEN 547/java
tcp 0 0 0.0.0.0:8200 0.0.0.0:* LISTEN 547/java
tcp 0 0 0.0.0.0:8009 0.0.0.0:* LISTEN 547/java
tcp 0 0 0.0.0.0:5900 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp6 0 0 :::5900 :::* LISTEN -
tcp6 0 0 :::8080 :::* LISTEN -
tcp6 0 0 :::22 :::* LISTEN
这表明MySQL服务器仍在tcp6上运行,端口是8080,我从标准3600更改了它。我的java主类如下:`public static String IP; // MySQL服务器IP的NULL变量 public static final String用户=“用户”; // mySQL服务器的用户名 public static final String password =“ pass”; // mySQL服务器TODO的密码了解如何隐藏密码 静态连接conn; // NULL连接以连接到mySQL服务器 公共静态扫描仪控制台= new Scanner(System.in); //用于从控制台获取数字和字符串
/**
* Runs the program
* @param args
*/
public static void main(String[] args) {
System.out.print("Internal or External IP (1 for Internal or 2 for external): ");
int choice = console.nextInt();
switch (choice){
case 1:
IP = "10.0.0.183";
break;
case 2:
IP = "external ipv4 address";
break;
}
//TRY CATCH method to ensure that the mySQL connection was successful
try{
conn = DriverManager.getConnection("jdbc:mysql://"+IP+":8080/mydb",user,password);
}catch(SQLException e){
System.out.println(e.getLocalizedMessage());
System.exit(1);
}`
这是我尝试连接到外部IPV4地址“通信链接失败”时遇到的错误
成功发送到服务器的最后一个数据包是0毫秒前。驱动程序尚未从服务器收到任何数据包。
有人有解决方案或需要我提供其他帮助以解决此问题!谢谢!
答案 0 :(得分:0)
您是否使用此10.0.0.183创建了MySQL用户? 请以此创建MySQL用户并提供授权并进行检查