You cannot.
If the user has a direct access to the application (they can directly launch it) everything that is hardcoded in the application should be seen as accessible to the user. Whatever obfuscation you can use, a determinated attacker will be able to find it (through decompilers an debuggers).
If a break point exist, all is different:
front end application back end application
launched by user --/--> launched with a sytem user
local machine local or remote machine
This is typically the use case for web applications: the user has no access to the application code, and does not launch it, so the database password can lie in a configuration file - it will always be accessible to administrators. Even when all runs on the same machine, decent OS allows for access protection to prevent unprivileged users any access to the backend program. For that latter case, the front end and backend can communicate through sockets, named pipes, messages or almost any other IPC mechanism.
TL/DR: only secure way:
- split the application into a front end running under user account with no knowledge of the database server, and a back end running under a system (non admin) user
- ensure that normal users have no access to the backend application files
- store the database password in a configuration file of the backend (never in a source file)