Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-05-2007, 05:16 PM
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-07-2007, 08:39 AM
Member
 
Join Date: Jul 2007
Posts: 40
toby is on a distinguished road
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).
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-18-2007, 10:32 AM
Member
 
Join Date: Jul 2007
Location: bangalore,india
Posts: 19
varunthecool is on a distinguished road
instead of
catch(SQLException e)
use catch(Exception e)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
help with these errors oceansdepth New To Java 3 04-16-2008 05:55 PM
Errors I don't understand MattyB New To Java 4 04-02-2008 12:55 AM
Handling SQL Errors and Warnings Java Tip Java Tips 0 02-12-2008 10:37 AM
Trying to catch thread errors yelllow4u New To Java 2 08-07-2007 03:52 PM
Errors in constructor ai_2007 Advanced Java 0 07-01-2007 06:35 PM


All times are GMT +3. The time now is 04:58 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org