View Single Post
  #1 (permalink)  
Old 08-05-2007, 06:16 PM
coco coco is offline
Member
 
Join Date: Jul 2007
Posts: 39
coco is on a distinguished road
I have 3 errors after compiling
Hi, I have this code:

Code:
package mysql; import java.sql.*; public class Hello { Connection connection; private void displaySQLErrors(SQLException e) { System.out.println("SQLException: " + e.getMessage()); System.out.println("SQLState: " + e.getSQLState()); System.out.println("VendorError: " + e.getErrorCode()); } public Hello() { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); } catch(SQLException e) { System.err.println("Unable to find and load driver"); System.exit(1); } } public void connectToDB() { try { connection = DriverManager.getConnection("jdbc:mysql://localhost/accounts?user=&password="); } catch(SQLException e) { displaySQLErrors(e); } } public void executeSQL() { try { Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery("SELECT * FROM acc_acc"); while(rs.next()) { System.out.println(rs.getString(1)); } rs.close(); statement.close(); connection.close(); } catch(SQLException e) { displaySQLErrors(e); } } public static void main(String[] args) { Hello hello = new Hello(); hello.connectToDB(); hello.executeSQL(); } }
I have 3 errors after compiling:
Code:
C:\Program Files\Xinox Software\JCreator LE\MyProjects\Hello.java:15: unreported exception java.lang.ClassNotFoundException; must be caught or declared to be thrown the second: C:\Program Files\Xinox Software\JCreator LE\MyProjects\Hello.java:15: unreported exception java.lang.ClassNotFoundException; must be caught or declared to be thrown the third: C:\Program Files\Xinox Software\JCreator LE\MyProjects\Hello.java:17: exception java.sql.SQLException is never thrown in body of corresponding try statement.
How can i solve it?
Thanks.
Reply With Quote
Sponsored Links