Help Center/
GaussDB/
Developer Guide(Distributed_8.x)/
Application Development Guide/
Development Based on JDBC/
Closing a Database Connection
Updated on 2024-06-03 GMT+08:00
Closing a Database Connection
After you complete required data operations in a database, close the database connection.
Call the close method to close the connection.
// There will be security risks if the username and password used for authentication are directly written into code. It is recommended that the username and password be stored in the configuration file or environment variables (the password must be stored in ciphertext and decrypted when being used) to ensure security. // In this example, the username and password are stored in environment variables. Before running this example, set environment variables EXAMPLE_USERNAME_ENV and EXAMPLE_PASSWORD_ENV in the local environment (set the environment variable names based on the actual situation). String userName = System.getenv("EXAMPLE_USERNAME_ENV"); String password = System.getenv("EXAMPLE_PASSWORD_ENV"); Connection conn = DriverManager.getConnection(sourceURL, userName, password); conn.close();
Parent topic: Development Based on JDBC
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot