我正在尝试将数据库连接到我的项目(在PhpStorm中),以便自动完成。
我要获取错误的步骤:
MySQL DataSource
TEST CONNECTION
按钮我已经正确填写了数据库功能中的每个字段(主机,数据库,用户,密码)
s00vl9944624.fr.net.intra
animationqrc
animationqrc
jdbc:mysql://s00vl9944624.fr.net.intra:3306/animationqrc
错误是:
java.rmi.ConnectException:连接拒绝主机:127.0.0.1;嵌套的异常是: java.net.ConnectException:连接超时:connect
问题是,当我自己使用一个Java类,该Java类仅尝试连接到服务器并从表中打印行时,它可以工作。
import java.sql.*;
class MysqlCon{
public static void main(String args[]){
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://s00vl9944624.fr.net.intra:3306/pilconquete?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC","*user*","*pass*");
//here sonoo is the database name, root is the username and root is the password
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from Admin_list");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
con.close();
}catch(Exception e){ System.out.println(e);}
}
}
"C:\Users\b96297\AppData\Local\JetBrains\PhpStorm 2018.2.3\jre64\bin\java" MysqlCon
Thu Sep 20 16:14:02 CEST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
3 497764 Xavier *******
即使我添加了PhpStorm默认参数(您可以在下面的日志中看到),也包括类路径。
"C:\Users\b96297\AppData\Local\JetBrains\PhpStorm 2018.2.3\jre64\bin\java" -Djava.net.preferIPv4Stack=true -Djava.rmi.server.hostname=127.0.0.1 -Duser.timezone=UTC -Dfile.encoding=UTF-8 MysqlCon
当我添加classpath参数时,Java找不到我的类。
我正在使用Win7 x64,PhpStorm 2018.2.3(在2017.3.3中也失败)。我在工作,所以防火墙可能适用网络限制。而且我的笔记本电脑没有管理员权限。
感谢您的帮助
编辑:
从PhpStorm日志中:
2018-09-20 15:54:25,481 [ 81612] INFO - ution.rmi.RemoteProcessSupport - "C:\Users\b96297\AppData\Local\JetBrains\PhpStorm 2018.2.3\jre64\bin\java" -Djava.net.preferIPv4Stack=true -Djava.rmi.server.hostname=127.0.0.1 -Duser.timezone=UTC -Dfile.encoding=UTF-8 -classpath "C:\Users\b96297\AppData\Local\JetBrains\PhpStorm 2018.2.3\lib\util.jar;C:\Users\b96297\AppData\Local\JetBrains\PhpStorm 2018.2.3\lib\trove4j.jar;C:\Users\b96297\AppData\Local\JetBrains\PhpStorm 2018.2.3\lib\groovy-all-2.4.15.jar;C:\Users\b96297\AppData\Local\JetBrains\PhpStorm 2018.2.3\plugins\DatabaseTools\lib\jdbc-console.jar;C:\Users\b96297\AppData\Local\JetBrains\PhpStorm 2018.2.3\plugins\DatabaseTools\lib\dekaf-single-2.0.0.372.jar;C:\Users\b96297\.PhpStorm\config\jdbc-drivers\MySQL Connector\J\5.1.46\mysql-connector-java-5.1.46.jar;C:\Users\b96297\Downloads\mysql-connector-java-8.0.12.jar" com.intellij.database.remote.RemoteJdbcServer com.mysql.cj.jdbc.Driver
2018-09-20 15:54:25,701 [ 81832] WARN - ution.rmi.RemoteProcessSupport - Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
2018-09-20 15:54:26,310 [ 82441] INFO - ution.rmi.RemoteProcessSupport - Port/ID: 30227/RemoteDriverImpl3260ec8e
2018-09-20 15:54:46,310 [ 102441] WARN - ution.rmi.RemoteProcessSupport - java.rmi.NotBoundException: _DEAD_HAND_
2018-09-20 15:54:46,310 [ 102441] WARN - ution.rmi.RemoteProcessSupport - at sun.rmi.registry.RegistryImpl.lookup(RegistryImpl.java:209)
2018-09-20 15:54:46,310 [ 102441] WARN - ution.rmi.RemoteProcessSupport - at com.intellij.execution.rmi.RemoteServer.start(RemoteServer.java:96)
2018-09-20 15:54:46,310 [ 102441] WARN - ution.rmi.RemoteProcessSupport - at com.intellij.database.remote.RemoteJdbcServerBase.setupAndStart(RemoteJdbcServerBase.java:20)
2018-09-20 15:54:46,310 [ 102441] WARN - ution.rmi.RemoteProcessSupport - at com.intellij.database.remote.RemoteJdbcServer.main(RemoteJdbcServer.java:14)
2018-09-20 15:54:47,334 [ 103465] WARN - ution.rmi.RemoteProcessSupport - The cook failed to start due to java.net.ConnectException: Connection timed out: connect
2018-09-20 15:54:47,335 [ 103466] INFO - ution.rmi.RemoteProcessSupport - Process finished with exit code 1
2018-09-20 15:54:47,339 [ 103470] WARN - lij.database.util.ErrorHandler - java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection timed out: connect
java.lang.RuntimeException: java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection timed out: connect
答案 0 :(得分:2)
总结一下我的评论,看来PhpStorm使用单独的Java进程将数据库访问与应用程序的其余部分隔离开。看起来这两个进程之间无法进行通信(使用RMI,远程方法调用)。
这可能是防火墙问题。如果您使用的是Windows,请在PhpStorm安装的OpenJDK Platform Binary的允许的应用程序配置下检查Windows防火墙设置(查看其详细信息,在您的情况下,路径应为C:\Users\b96297\AppData\Local\JetBrains\PhpStorm 2018.2.3\jre64\bin\java
),然后启用 Private < / em>访问(在某些情况下,您可能还需要尝试 Public )。这将允许Java进程使用RMI进行通信。
如果在防火墙配置中找不到OpenJDK平台二进制文件,请从PhpStorm安装的java.exe
文件夹中添加jre64\bin
并进行配置。
答案 1 :(得分:1)
与@MarkRotteveel和Dmitry Tronin讨论后| JetBrains的支持工程师 我学到了一些发现: