Note that there are some explanatory texts on larger screens.

plurals
  1. POtry and catch error
    text
    copied!<pre><code>public class ConnectionManager { private static String url = "jdbc:mysql://localhost:3306/prototypeeop"; private static String driverName = "com.mysql.jdbc.Driver"; private static String usernsme = "root"; private static String pasword = "triala"; private static Connection con; private static String url; public static Connection getConnection() { try { Class.forName(driverName); try { con = DriverManager.getConnection(url, username, password); } catch (SQLException ex) { // log an exception. fro example: System.out.println("Failed to create the database connection."); } } catch (ClassNotFoundException ex) { // log an exception. for example: System.out.println("Driver not found."); } return con; } } </code></pre> <p>Hey, I am making this class, and I get a "classnotfound exception is never thrown in body of corresponding try statement"? This has something to do with my try and catch block, and I am wondering what the problem is. It says for the try error that, "unreported exception java.lang.classnotfound excpetion must be caught or declared before it is thrown".</p> <p>I apologize for the obvious questions, but I am new to try and catch blocks too. I know it has something to do with me not declaring this type of error because the SQLException has been declared in the java.sql package; hence, why I don't get an error. (I include "import java.sql package" in my code since I am using the Connection class for JDBC). The class basically sets up a connection and returns that connection.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload