简体   繁体   English

如何使用Java获取数据库状态?

[英]How to get the db status using java?

I am new to the java programing and trying to develop an application. 我是java编程和尝试开发应用程序的新手。 On my jsp page I am allowing user to enter the db details and then click on test button to check whether connection is set or not. 在我的jsp页面上,我允许用户输入数据库详细信息,然后单击“测试”按钮以检查是否已设置连接。

You can catch the SQLException from DriverManager.getConnection(). 您可以从DriverManager.getConnection()捕获SQLException。 By this you can validate the connection. 这样,您可以验证连接。

If there is no Exception occurred while connecting with the given database details 如果与给定的数据库详细信息连接时未发生异常
you can tell connection is success.Else catch the exception and show message accordingly to the user 您可以判断连接成功。否则捕获异常并向用户显示消息

您可以使用jdbc触发"select 1"查询,并且如果没有引发任何异常,则可以说连接已完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM