Java数据库连接失败,预期响应。

huangapple go评论77阅读模式
英文:

Java Database Connection failing, Respone expected

问题

我有一段 Java 代码出现了问题;具体来说,我正在尝试与数据库建立连接。代码基本上是有效的,但我注意到会收到一个提示,通知用户凭据,例如密码,将在7天后过期;当这种情况发生时,代码会失败,因为没有得到响应。我该如何处理这种情况?对于目标数据库,我在用户供应方面的控制有限,而该数据库在这种情况下是一个 AS400 服务器。

这是我的代码:

Class.forName("com.ibm.as400.access.AS400JDBCDriver");
Connection connection = null;
try {
    connection = DriverManager.getConnection(url, username, password);
} catch (Exception e) {
    e.printStackTrace();
}

感谢任何帮助。

英文:

I have some Java code that is failing; specifically I am trying to make a connection to a database. The code works in general however I have observed that a prompt will be given notifying that the user credentials, the password will expire in 7 days as an example; when this happens the code fails as no response is given. How can I handle this case? I have limited control over user provisioning for the target database, which in this case is an AS400 server.

Here is my code:

Class.forName("com.ibm.as400.access.AS400JDBCDriver");
Connection connection = null;
try {
    connection = DriverManager.getConnection(url, username, password);
} catch (Exception e) {
	e.printStackTrace();
}

Any help is appreciated.

答案1

得分: 1

你需要与系统管理员联系,获取一个不会过期的应用程序服务配置文件。这是你能做的全部。如果你没有有效的用户ID和密码,就无法连接。或者你可以在每次启动应用程序时提示用户输入用户ID和密码,然后用户可以输入他们的用户ID和密码。然后你就可以使用那些信息进行连接。

英文:

You are going to have to get in touch with the system admin and get a service profile for your application that does not expire. That is all you can do. If you don't have a valid user id and password, you can't connect. Or you could prompt for a user id and password each time you start the application, and have the user enter their user id and password. Then you can connect with that.

答案2

得分: 0

使用JDBC URL上的prompt=false连接属性来禁用提示。

connection = DriverManager.getConnection(url+";prompt=false", username, password);

有关其他JDBC属性,请参阅以下内容。http://jt400.sourceforge.net/doc/com/ibm/as400/access/doc-files/JDBCProperties.html

英文:

Use the prompt=false connection property on the JDBC URL to disable the prompting.

connection = DriverManager.getConnection(url+";prompt=false", username, password);

See the following for additional JDBC properties. http://jt400.sourceforge.net/doc/com/ibm/as400/access/doc-files/JDBCProperties.html

huangapple
  • 本文由 发表于 2020年8月22日 04:32:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/63529738.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定