i know this is checked exception but how to identify that there i have to declare it otherwise code wont compile ? i am just using methods i don't know their source code.
Joined: May 30, 2011
but each method contains javadoc, and each javadoc section contains information about "throws Exceptions"
public ResultSet executeQuery(String sql)
Executes the given SQL statement, which returns a single ResultSet object.
sql - an SQL statement to be sent to the database, typically a static SQL SELECT statement
a ResultSet object that contains the data produced by the given query; never null
SQLException - if a database access error occurs or the given SQL statement produces anything other than a single ResultSet object
Ravan Kumar wrote:i know this is checked exception but how to identify that there i have to declare it otherwise code wont compile ? i am just using methods i don't know their source code.
The javadoc for that method tells you what checked exceptions it throws. The javadocs for each of those exceptions tell you whether they are checked or unchecked. Knowing the basic rules of checked and unchecked exceptions in Java tells you that you have to catch or declare the checked exceptions that method can throw. There's no need for its source code.