java - 使用 Selenium 连接到数据库时出现未知主机异常
问题描述
当我连接到客户端网络(使用 VPN)时,我可以成功地从数据库中获取数据。但是,如果我断开与客户端网络的连接并在本地运行相同的功能,那么我将遇到错误 -
连接失败:SAP DBTech JDBC:无法连接到 jdbc:sap://saphsg.XXXX.XX.com:30015 [未知主机 saphsg.XXXX.XXX.com:30015 [null],-709]。
下面是我正在使用的代码 -
public static void dbConnection(String query) throws ClassNotFoundException {
Connection connection = null;
try {
Class.forName("com.sap.db.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:sap://saphsg.XXXX.XXX.com:30015?encrypt=true&validateCertificate=false", UserID, Password);
} catch (SQLException e) {
System.err.println("Connection Failed:" +e.getMessage());
}
if (connection != null) {
try {
System.out.println("Connection to HANA successful!");
Statement stmt = connection.createStatement();
ResultSet resultSet = stmt.executeQuery(query);
while (resultSet.next()){
String Name1 = resultSet.getString(1);
String Name2 = resultSet.getString(4);
String Name3 = resultSet.getString(5);
System. out.println(Name1+"----"+Name2+"----"+Name3);
}
} catch (SQLException e) {
System.err.println("Query failed!");
}
}
}
解决方案
推荐阅读
- batch-file - TestNG 失败后如何使詹金斯的工作变得不稳定
- firebase - Firebase 错误:“错误解析触发器:找不到模块 './clone.js'”
- python - 一起运行两个 Python 应用程序?
- javascript - 带有暂停和恢复轮询的 Rxjs 计时器
- image - Image Magick 不处理所有图像
- http - Flutter - 尽管状态代码错误,如何启动 URL
- mysql - SQL 间歇性地不返回任何数据以响应 LEFT JOIN
- python - Python:提取特定列数据并将其存储到变量中
- google-cloud-platform - 权限被拒绝 - GCP 云资源管理器 setIamPolicy
- java - Spring覆盖另一个模块的bean