You are not checking whether your result set has any data or row in it.
ResultSet rs = stmt.executeQuery();
rs.next();
...
...
You should check whether your result is empty or having any row:
ResultSet rs = stmt.executeQuery();
if(rs.next()){
.....
your code
.....
}
More Related Contents:
- What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it?
- How can I solve “java.lang.NoClassDefFoundError”?
- What are the effects of exceptions on performance in Java?
- How to generate exceptions from RepaintManager
- ClassNotFoundException com.mysql.jdbc.Driver [duplicate]
- How to create custom exceptions in Java? [closed]
- Given final block not properly padded
- Null check chain vs catching NullPointerException
- Why does division by zero with floating point (or double precision) numbers not throw java.lang.ArithmeticException: / by zero in Java
- When should we create our own Java exception classes? [closed]
- How to test that no exception is thrown?
- Using Joda Date & Time API to parse multiple formats
- How to create a custom exception type in Java? [duplicate]
- Why are Exceptions not Checked in .NET?
- Java: Exceptions as control flow?
- Closing a Scanner throws java.util.NoSuchElementException
- “NoClassDefFoundError: Could not initialize class” error
- What is a suppressed exception?
- In a Java 7 multicatch block what is the type of the caught exception?
- What are reasons for Exceptions not to be compatible with throws clauses?
- In Java how can I validate a thrown exception with JUnit?
- The throws keyword for exceptions in Java
- Exception other than RuntimeException
- Getting Exception org.apache.logging.slf4j.SLF4JLoggerContext cannot be cast to org.apache.logging.log4j.core.LoggerContext
- Exception in thread “main” java.io.FileNotFoundException: Error
- Is it a bad idea to use printStackTrace() for caugt Exceptions?
- Is there an unhandled exception handler in Java?
- The local variable might not have been initialized – Detect unchecked exception throw within a method
- org.openqa.selenium.UnhandledAlertException: unexpected alert open
- Side effects of throwing an exception inside a synchronized clause?