Results 1 to 3 of 3
Thread: I have 3 errors after compiling
- 08-05-2007, 04:16 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 39
- Rep Power
- 0
I have 3 errors after compiling
Hi, I have this code:
I have 3 errors after compiling:Java 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(); } }
How can i solve it?Java 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.
Thanks.
- 08-07-2007, 07:39 AM #2
Member
- Join Date
- Jul 2007
- Posts
- 40
- Rep Power
- 0
Class.forName() doesn't throw an SQLException, but it might throw a ClassNotFoundException if the class doesn't exist in it's classpath. So instead of catching an SQLException you should be catching a ClassNotFoundException (or something above it in the hierarchy like Exception).
- 10-18-2007, 09:32 AM #3
Member
- Join Date
- Jul 2007
- Location
- bangalore,india
- Posts
- 19
- Rep Power
- 0
Similar Threads
-
help with these errors
By oceansdepth in forum New To JavaReplies: 3Last Post: 04-16-2008, 04:55 PM -
Errors I don't understand
By MattyB in forum New To JavaReplies: 4Last Post: 04-01-2008, 11:55 PM -
Handling SQL Errors and Warnings
By Java Tip in forum Java TipReplies: 0Last Post: 02-12-2008, 09:37 AM -
Trying to catch thread errors
By yelllow4u in forum New To JavaReplies: 2Last Post: 08-07-2007, 02:52 PM -
Errors in constructor
By ai_2007 in forum Advanced JavaReplies: 0Last Post: 07-01-2007, 05:35 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks