Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Find server which is servicing the request

User_19BPUNov 28 2016 — edited Dec 5 2016

Hi,

I have 5 Prod servers which are clustered, hence the request may go to any of the Prod servers based on the load balancing setup, there are cases we found that a particular service say customer service is up and running in server 1,2, 3 but it is down in server 4 & 5. In such case the if request hits either server 4 or 5 , the request is not processed and we are getting an error stating the customer service is down in the respective server logs in this case it is in server 4 logs. Now I want to send an email to respective user via Java application when the service is down in any one of the 5 servers for which the request is send? how I can use the java code to find the request is send to which server? and how I can get the server name/IP address which is not able to service the request because the respective customer service is down.

Thanks

Comments

_AZ_

i think i should elaborate that I do expect to receive only one row ( from the select). Anything more (or less) should be deemed an error.

Answer

Well, with the code you have above you *will* get an error: TypeError: 'NoneType' object is not iterable. The reason for that is that fetchone() returns None if there are no rows left to fetch. That error isn't too helpful, though. You will need to do something along these lines:

row = cursor.fetchone()

if row is None:

   raise Exception("Hey, only one row was returned!")

tim, val = row

You will want to replace the Exception message with something a bit more meaningful, of course!

Marked as Answer by _AZ_ · Sep 27 2020
_AZ_

thank you @Anthony . Is there a better approach that i should.could use ( vs fetchone or overall ) ?

You're welcome. That approach works and is reasoanble. If you want to check for too many rows as well, you can do fetchall() which will return an array and check the length of the array instead. If you're worried about getting back too many rows with fetchall() you can also use fetchmany(2) which will tell you if there are 0, 1, or 2 rows available.

1 - 4
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jan 2 2017
Added on Nov 28 2016
4 comments
220 views