This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes JSP and the fly likes Catching an error... faster Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Catching an error... faster" Watch "Catching an error... faster" New topic
Author

Catching an error... faster

George Larry
Ranch Hand

Joined: Nov 07, 2001
Posts: 52
On my web page I have a login screen where they're actually logging into the Oracle db (using an Oracle login- just as they would when logging directly into Oracle from SQL*Plus or something). I had the following... (more or less)
String logUser = request.getParameter( "logUser" );
String logPass = request.getParameter( "logPass" );
try {
// Load the Oracle JDBC driver
DriverManager.registerDriver( new oracle.jdbc.driver.OracleDriver() );
String url = "jdbc racle:thin:@blah:1521:mis";
Connection con = DriverManager.getConnection( url, logUser, logPass );
con.close();
} catch ( Exception e ) {
errorMessage = "Invalid username/password. Please check them and try again.";
}
This works, but if the login is incorrect... it seems to take a very long time to let me know. I think the problem is with the try... it just keeps on trying. So, I think I want to try something like this...
// Load the Oracle JDBC driver
DriverManager.registerDriver( new oracle.jdbc.driver.OracleDriver() );
String url = "jdbc racle:thin:@blah:1521:mis";
if ( ( DriverManager.getConnection( url, logUser, logPass ) ).equals( "Error: java.sql.SQLException: ORA-01017: invalid username/password; logon denied" ) ) {
errorMessage = "Login failed";
}
This doesn't work, though... I'm not sure how to catch that error- without using a try, but the try seems to take too long. Also, I don't want to leave any hanging sessions in Oracle.
Does anyone have any ideas on how to make this work... fast?
Byron Estes
Ranch Hand

Joined: Feb 21, 2002
Posts: 313
George,
I don't think your issue is not that the try takes so long. The problem could be related to connections which may be left open.

Remember, the exception will be thrown on an invalid attempt during the getConnection() call. When the exception occurs it goes directly to the catch block.
1)Make sure no connections are outstanding on your dbms.

2) Add a finally clause to your try where you check to see if the con variable is not equal to null. If it's not equal to null, then close() it.
Try/catch blocks are a great programming construct and should be embraced. Also, the code you want to implement cannot be done without coding a try/catch somewhere. You can throw it up from the current method by adding a throws clause to that method, but eventually some code must catch it or it eventually results in a runtime error.
Regards,


Byron Estes<br />Sun Certified Enterprise Architect<br />Senior Consulant<br />Blackwell Consulting Services<br />Chicago, IL<br /><a href="http://www.bcsinc.com" target="_blank" rel="nofollow">www.bcsinc.com</a>
George Larry
Ranch Hand

Joined: Nov 07, 2001
Posts: 52
Ok, Here's what I've got now... but it still seems to be taking quite a while when the login fails. A successful login occurs super-fast. Am I missing something that might cause a bad login to lag?

Thank you.
[ July 31, 2002: Message edited by: George Larry ]
[ July 31, 2002: Message edited by: George Larry ]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
As I recall, registering the driver only has to be done once. You should be doing that in a jspInit() method.
How long does it take to reject a login when you are outside the JSP environment?
Bill
George Larry
Ranch Hand

Joined: Nov 07, 2001
Posts: 52
In a SQL*Plus shell it takes about .5 seconds to tell me if a login is correct or incorrect. Using the jsp it takes about 1 second for a correct login, but over 1 minute for an incorrect one.
Byron Estes
Ranch Hand

Joined: Feb 21, 2002
Posts: 313
George,
Pretty wierd.
-It's not the network, since it's consistently fast on success and slow on failure.
Maybe it the dbms itself. Take a look at the error logging. Maybe it's getting full, maybe it's set to verbose or something like that...
These are shots in the dark, take them for what they are worth.
Hope you solve it,
 
Don't get me started about those stupid light bulbs.
 
subject: Catching an error... faster