Is there a way to log the username of a failed Oracle login in Java? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Is there a way to log the username of a failed Oracle login in Java? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

We have a number of development environments and an application that opens 20+ logins to our database in each environment.

Every time someone misconfigures an application, we get a log entry that says simply:

java.sql.SQLException: ORA-01017: invalid username/password; logon denied

This happens a lot, and it would simplify life tremendously if either Spring Framework, Oracle or Apache Tomcat could be configured to report the username that could not log in.

This usually happens during application startup when Spring is wiring the beans for the application, so I’m not sure if our code (e.g., custom error pages) is even available yet.

Anyone have any cool ideas about how to do this?

Answer

At the database level, you can enable AUDIT TRAIL to log all the login details. It could be done by setting the audit_trail parameter to true.

show parameter audit_trail

Once enabled for unsuccessful logons, all failed logon attempts will be directed to the database audit trail SYS.AUD$ table. You could query dba_audit_trail to fetch the details:

select 
   os_username,
   username,
   terminal,
   to_char(timestamp,'MM-DD-YYYY HH24:MI:SS')
from
   dba_audit_trail;
We are here to answer your question about Is there a way to log the username of a failed Oracle login in Java? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji