Unreported exception

hi all,
what is the problem to cause the error?? please teach me. thanks.
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\examples\jsp\HMC\HTML\testDL3_jsp.java:76: unreported exception java.sql.SQLException; must be caught or declared to be thrown
Connection c = DriverManager.getConnection(
^
An error occurred at line: 9 in the jsp file: /jsp/HMC/HTML/testDL3.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\examples\jsp\HMC\HTML\testDL3_jsp.java:79: unreported exception java.sql.SQLException; must be caught or declared to be thrown
Statement s = c.createStatement();
^
An error occurred at line: 9 in the jsp file: /jsp/HMC/HTML/testDL3.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\examples\jsp\HMC\HTML\testDL3_jsp.java:140: unreported exception java.sql.SQLException; must be caught or declared to be thrown
s.executeUpdate(sql);
^
An error occurred at line: 9 in the jsp file: /jsp/HMC/HTML/testDL3.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\examples\jsp\HMC\HTML\testDL3_jsp.java:154: unreported exception java.sql.SQLException; must be caught or declared to be thrown
     c.close();
^

Either put your code in try / catch(SQLException)/ finally blocks, either declare the method where your code resides to throw a SQLException, using the throws clause.
Google for any JDBC code and you'll see countless examples on how to do this.

Similar Messages

  • Generic throws clause causes unreported exception

    I'm trying to pass a block to a ctor, which can throw an exception. The problem can be reproduced with this sample program.
    interface Bar<X extends Exception> {
        void run() throws X;
    public class Foo {
        public Foo() {}
        public <X extends Exception> Foo(Bar<X> bar) throws X {
            bar.run();
        public static <X extends Exception> Foo createFoo(Bar<X> bar) throws X {
            return createFoo2(bar); // ok
        public static <X extends Exception> Foo createFoo2(Bar<X> bar) throws X {
            Foo foo = new Foo();
            bar.run(); // ok
            return foo;
        public static <X extends Exception> Foo createFoo3(Bar<X> bar) throws X {
            return new Foo(bar);  // unreported exception X; must be caught or declared to be thrown
    }createFoo and createFoo2 work fine, but createFoo3 fails to compile with javac. None of the examples raise a warning in IDEA. I'm running javac 1.5.0_07.
    Is there a way to do this in Java 1.5, or is this a bug with javac?

    BrianEgge wrote:
    However, we know types inference works differently for methods vs constructors (15.12.2.8). This is why List<String> s = Collections.emptyList(); works, but List<String> s = new ArrayList<String>() generates an unchecked warning. Well, this is definitely not true.
    According the the JLS, the throws clause shouldn't be handled differently.
    8.8.5 Constructor Throws
    The throws clause for a constructor is identical in structure and behavior to the throws clause for a method (�8.4.6).The JLS explicitely allows a constructor to be defined generic, and those parameters have a scope on the constructor definition including the parameter list (8.8.4 Generic Constructors).
    Hence, I assume, this is a bug.

  • Unreported exception java.lang.Exception; must be caught or declared

    I've got a piece of code that's causing an error during compilation.
    W:\Java\Covenant\src\covenant\Login.java:174: unreported exception java.lang.Exception; must be caught or declared to be thrownThe line of code it is refering to is:
    new Overview().setVisible(true);And it is part of a try/catch statement:
        private void logincheck(java.awt.event.ActionEvent evt) {                           
            try {
                char[] PasswordInput = Password.getPassword();
                String PasswordRaw = new String(PasswordInput);
                String Passwordmd5 = md5(PasswordRaw);
                String UsernameInput = Username.getText();
                URL theUrl = new URL("http://www.phoenixrising.at/iris/validate.php?login=1&u=" + UsernameInput + "&p=" + Passwordmd5 +"");
                BufferedReader in = new BufferedReader(
                        new InputStreamReader(
                        theUrl.openStream()));
                String inputLine = in.readLine();
                if (inputLine.equals("valid")) {
                    new Overview().setVisible(true);
                    this.setVisible(false);
                    System.out.println( "You have entered the correct password" );
                } else {
                    System.out.println(theUrl);
                in.close();
            } catch (MalformedURLException ex) {
                ex.printStackTrace();
            } catch (IOException ex) {
                ex.printStackTrace();
        }      Can anyone see what might be causing this error?

    Can anyone see what might be causing this error? That line of code declares that it throws exception java.lang.Exception, so you must either catch it ("must be caught" - like you do the more specific Exceptions) or declare your logincheck method to throw it ("or declared to be thrown").

  • Unreported exception java.rmi.RemoteException; must be caught or declared t

    I am receiving an:
    unreported exception java.rmi.RemoteException; must be caught or declared to be thrown
    error when I attempt to compile the Client.java file.
    The Client.java file implements the ATMListener.java interface.
    As you will see below, I've stripped them down by taking out all of the code, yet I still receive this error.
    Any ideas...
    ATMListener.java
    import java.rmi.*;
    import java.rmi.server.UnicastRemoteObject;
    * @author Eddie Brodie
    * @version %I%, %G%
    public interface ATMListener extends java.rmi.Remote
    Client.java
    import java.net.MalformedURLException;
    import java.rmi.Naming;
    import java.rmi.NotBoundException;
    import java.rmi.RemoteException;
    import java.rmi.UnknownHostException;
    public class Client extends java.rmi.server.UnicastRemoteObject implements ATMListener

    Well first off unless I am missing something in the API java.rmi.Remote is an interface not a class so implements not inherits, but I do not really know these classes so I cannot be sure I am not missing something.
    As for the unreported exception. What could be causing something like this would be an exception thrown by the constructor of the parent class. Even if you have no constructor written for your class it still has a default constructor which will by default call the super constrcutpor meaning an exception could be thrown from the super constrcutor down to your default constructor where you would not know what to do with it.

  • Unreported exception; java.sql.SQLException; must be caught or declared to

    Hi everyone,
    For my Java course assignment we need to make a small application that uses a MS Access database. But de code below gives me a "Unreported exception; java.sql.SQLException; must be caught or declared to be thrown at line xx" error.
    public class ConnectieBeheer
      private static Connection con;
      private static Statement stmt;
      private static ResultSet res;
      private static ResultSetMetaData md;
      private ConnectieBeheer(){}
      public static void openDB() {
        Driver driver = new JdbcOdbcDriver();
        Properties info = new Properties();
        String url = "jdbc:odbc:theater";
        con = driver.connect(url, info);       <--- Error here
        if (con != null)
          stmt =  con.createStatement();      <--- Error here
          DatabaseMetaData dma = con.getMetaData();      <--- Error here
      }So I tried this :
    public static void openDB() throws SQLException {Now I do not get an error.
    The OpenDB method is called from a different class like this :
      public static void test1(){
        ConnectieBeheer.openDB();
        System.out.println("DB opened");
      }But now it gives the same "Unreported exception; java.sql.SQLException; must be caught or declared to be thrown at line xx" error but now at the line ConnectieBeheer.openDB();
    Why is this? And what can I do to correct this?
    Thanks!
    Steven.

    you should read the sun tutoriel about exceptions handling ;
    there are two ways to handle an exception : either you redirects it (using "throws" statement, what you did for the openDB method), or you catch it using a try { ... } catch (Exception exc) {}
    if you want to get rid of the error what you can do is :
      public static void test1(){
        try {
            ConnectieBeheer.openDB();
        } catch (java.sql.SQLException sqle) {
            sqle.printStackTrace();
        System.out.println("DB opened");
      }

  • How to slove follwoing error "Unreported exception java.io.IOException;"

    Currently I'm using following:
    XP Professional
    J2sdk1.4.2_01
    Xerces-2_5_0
    Xalan-j_2_5_1
    Jakarta-tomcat-4.1.27
    Jdom-b9
    Current Classpath setting
    User variables
    PATH = c:\bmrt2.5\bin; c:\j2sdk\bin;%PATH%;%JAVA_HOME%\bin;
    CLASSPATH=.;c:\xerces\xmlParserAPIs.jar;c:\xerces\xercesImpl.jar;
    c:\xerces\xercesSamples.jar;c:\xalan\xercesImpl.jar;c:\xalan\xmlapis.jar;c:\xalan\xalan.jar;c:\tomcat\lib\webserver.jar;c:\tomcat\lib\jasper.jar;c:\tomcat\lib\xml.jar;c:\tomcat\common\lib\serlet.jar;c:\tomcat\lib\tools.jar; c:\tomcat\lib\tools.jar;c:\jdom\build\jdom.jar;
    CATALINA_HOME= c:\tomcat
    JAVA_HOME= c:\j2sdk
    System variables
    PATH=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;
    c:\j2sdk\bin;%Path%;%JAVA_HOME%\bin;
    CLASSPATH=.;c:\xerces\xmlParserAPIs.jar;c:\xerces\xercesImpl.jar;
    c:\xerces\xercesSamples.jar;c:\xalan\xercesImpl.jar;c:\xalan\xmlapis.jar;c:\xalan\xalan.jar;c:\tomcat\lib\webserver.jar;c:\tomcat\lib\jasper.jar;c:\tomcat\lib\xml.jar;c:\tomcat\common\lib\serlet.jar;c:\tomcat\lib\tools.jar; c:\tomcat\lib\tools.jar;
    CATALINA_HOME= c:\tomcat
    JAVA_HOME= c:\j2sdk
    Program
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import org.jdom.*;
    import org.jdom.Element;
    import org.jdom.Document;
    import org.jdom.output.XMLOutputter;
    import org.jdom.input.SAXBuilder;
    import org.jdom.Attribute;
    import java.util.List;
    public class AddToList extends HttpServlet
         public Document getDocument(File sourceFile, PrintWriter errorsOut)
              try
                   SAXBuilder builder = new SAXBuilder();
                   Document document = builder.build(sourceFile);
                   return document;
              catch(JDOMException e)
                   errorsOut.print("there was a problem building the document: " e. getMessage()"<br/>"+ "Returning blank document.");
                   return new Document(new Element("blank"));
         public void saveDocument(Document saveDoc, File saveFile, PrintWriter errorsOut)
              try
                   FileOutputStream outStream= new FileOutputStream(saveFile);
                   XMLOutputter outToFile= new XMLOutputter(" ",true);
                   outToFile.output(saveDoc, outStream);
                   outStream.flush();
                   outStream.close();
              catch (IOException e)
                   errorsOut.print("Can't save order.xml: " + e.getMessage()+"<br />");
         public void addItem(Element orderElement, String product_id, String quant)
              Element newItem =new Element("item");
              newItem.setAttribute("product_id", product_id);
              Element quantity =new Element("quantity");
              quantity.addContent(quant);
              newItem.addContent(quantity);
              orderElement.addContent(newItem);
         public void doGet(HttpServletRequest request, HttpServletResponse response)
              throws IOException, ServletException
              String thisProduct_id=request.getParameter("addProduct_id");
              String thisQuantity=request.getParameter("addQuantity");
              response.setContentType("text/html");
              PrintWriter out= response.getWriter();
              out.print("Adding "+ thisQuantity + "of item to chart "+ thisProduct_id +" ... ");
              File orderFile = new File ("file:///c:/jdk1.3/orders.xml");
              if(!orderFile.exists())
                   out.print("Creating ordersrocks....<br />");
                   Element root= new Element("orders");
                   root.addContent(" ");
                   Document document = new Document(root);
                   saveDocument (document, orderFile, out);
              else
                   out.print("Orders File Exists.");
              Document document =getDocument(orderFile, out);
              HttpSession session =request.getSession(true);
              String session_id= session.getId();
              Element root =document.getRootElement();
              List orders =root.getChildren();
              int num_orders =orders.size();
              boolean orderExists =false;
              int orderIndex =0;
              for(int i=0; i<num_orders; i++)
                   Element iOrder=(Element)orders.get(i);
                   String iOrder_id=iOrder.getAttributeValue("order_id");
                   if (iOrder_id.equals(session_id))
                        orderExists=true;
                        orderIndex=i;
                        break;
              if(!orderExists)
                   Element order =new Element("order");
                   order.setAttribute("order_id", session_id);
                   Element status =new Element("order_status");
                   status.setText("open");
                   order.addContent(status);
                   addItem(order, thisProduct_id, thisQuantity);
                   root.addContent(order);
              else
                   Element thisOrder=(Element)orders.get(orderIndex);
                   boolean itemExists=false;
                   int itemIndex =0;
                   List items =thisOrder.getChildren("item");
                   int num_items =items.size();
                   for(int i=0; i<num_items; i++)
                        Element iItem=(Element)items.get(i);
                        String iProduct_id =iItem.getAttribute("product_id").getValue();
                        if(iProduct_id.equals(thisProduct_id))
                             itemExists =true;
                             itemIndex =i;
                             break;
                   if(itemExists)
                        Element thisItem=(Element)items.get(itemIndex);
                        String currentQuantity= thisItem.getChildText("quantity");
                        int newQuantity = Integer.parseInt(currentQuantity)+ Integer.parseInt(thisQuantity);
                        String strQuantity= new String().valueOf(newQuantity)+1;
                        thisItem.getChild("quantity").setText(strQuantity);
                   else
                        addItem(thisOrder, thisProduct_id, thisQuantity);
              saveDocument (document, orderFile, out);
         public void doPost(HttpServletRequest request, HttpServletResponse response)
              throws IOException, ServletException
              doGet(request, response);
    When I compile above program, it gives me following error.
    Error
    C:\tomcat\webapps\book\WEB-INF\classes>javac AddToList.java
    AddToList.java:19: unreported exception java.io.IOException; must be caught
    or declared to be thrown
    Document document = builder.build(sourceFile);
    ^
    1 error
    Any help regarding this will be appreciated
    Thank you
    Rocks

    Obadare
    Thank for your help, my program compile successfully. But now I�m facing different kind of error on Tomcat; why it gives me following error and how do I solve it
    http://localhost:8080/rock/servlet/AddToList
    Following Error generate by Tomcat:
    Http Status 500-
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: Cannot allocate servlet instance for path /rock/servlet/AddToList
         at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:435)
         at org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:180)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
    (ApplicationFilterChain.java:247)
    root cause
    java.lang.NoClassDefFoundError: org/jdom/JDOMException
         at java.lang.Class.newInstance0(Native Method)
         at java.lang.Class.newInstance(Class.java:237)
         at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:903)
         at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:668)
         at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:416)
         at org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:180)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
    (ApplicationFilterChain.java:247)
    The following is my configuration
    Classpath= .;c:\xalan\bin\xalan.jar;c:\xalan\bin\xml-apis.jar;c:\xerces\xmlParserAPIs.jar;c:\xerces\xercesImpl.jar;c:\tomcat\common\lib\servlet.jar;c:\jdom\build\jdom.jar;
    Java_Home=c:\jdk1.3
    Catalina_Home=c:\tomcat
    Server.xml
    <Engine name="Standalone" defaultHost="localhost" debug="0">
    <Host name="localhost" debug="0" appBase="webapps"
    unpackWARs="true" autoDeploy="true">
    <Context path="/rock" docBase="rock" debug="0"
    reloadable="true" crossContext="true">
    P.S When I try to build javadoc it give me following error:
    C:\jdom>build javadoc
    JDOM Build System
    Building with classpath c:\jdk1.3\lib\tools.jar;.\lib\ant.jar;.\lib\xml-apis.jar
    ;.\lib\xerces.jar;
    Starting Ant...
    Buildfile: build.xml
    [javadoc] Constructing Javadoc information...
    [javadoc] Building tree for all the packages and classes...
    [javadoc] Building index for all the packages and classes...
    [javadoc] javadoc: warning - Tag @link: Class or Package not found: javax.xml.
    transform.TransformerFactory#getFeature
    [javadoc] javadoc: warning - Tag @link: Class or Package not found: javax.xml.
    transform.TransformerFactory#getFeature
    [javadoc] Building index for all classes...
    [javadoc] javadoc: warning - Tag @link: Class or Package not found: javax.xml.
    transform.TransformerFactory#getFeature
    [javadoc] javadoc: warning - Tag @link: Class or Package not found: javax.xml.
    transform.TransformerFactory#getFeature
    [javadoc] javadoc: warning - Tag @link: Class or Package not found: javax.xml.
    transform.Transformer
    [javadoc] javadoc: warning - Tag @link: Class or Package not found: javax.xml.
    transform.Transformer
    [javadoc] javadoc: warning - Tag @link: Class or Package not found: javax.xml.
    transform.Transformer JAXP TrAX Transformer
    [javadoc] javadoc: warning - Tag @link: Class or Package not found: javax.xml.
    transform.TransformerFactory#getFeature
    [javadoc] javadoc: warning - Tag @link: Class or Package not found: javax.xml.
    transform.TransformerFactory#getFeature
    [javadoc] javadoc: warning - Tag @link: Class or Package not found: java.lang.
    Double#NaN
    [javadoc] Generating C:\jdom\build\apidocs\stylesheet.css...
    [javadoc] 10 warnings
    BUILD SUCCESSFUL
    Total time: 12 seconds

  • Unreported exception--Need Help

    I can't understand why is this not working:
    import java.util.Properties;
    import javax.mail.*;
    import javax.mail.internet.*;
    public class Slanje {
         public void infos(String host,String from,String to,String subject,String messagetext){
    /*String host="";
    String from="";
    String to="";*/
    // Get system properties
    Properties props = System.getProperties();
    // Setup mail server
    props.put("mail.smtp.host", host);
    // Get session
    Session session = Session.getDefaultInstance(props, null);
    // Define message
    MimeMessage message = new MimeMessage(session);
    // Set the from address
    message.setFrom(new InternetAddress(from));
    // Set the to address
    message.addRecipient(Message.RecipientType.TO,
    new InternetAddress(to));
    // Set the subject
    message.setSubject(subject);
    // Set the content
    message.setText(messagetext);
    // Send message
    Transport.send(message);
    I'm making email client and want to make methods to be called when wanting to make message to be send

    I presume you're getting a compiler error regarding the unreported exception, right? That means you need to put your method calls that throw exceptions in a try/catch block. For example, props.put() throws NullPointerException, so you need a catch statement for that. The other method calls may have similar needs.
    Steve

  • Unreported Exception java.lang.InstantiationException

    Dear Friends,
    I am developing javabean connectivty for inserting records to mysql database from jsp. when i try to compile java bean program. It gives an error like unreported Exception java.lang.InstantiationException: Must be caught or declared to be thrown*. This is my mode. Please anyone help to solve this error. if you find any error in my code, please suggest me. Thanks in advance.
    package com.webdeveloper.servlets;
    import java.sql.*;
    import java.io.*;
    public class InsertBean {
    private String dbURL = "jdbc:mysql://localhost:3306/test";
    private Connection dbCon;
    private Statement st;
    String dbuser = "root";
    String dbpass = "admin";
    String Name = null;
    String Address = null;
    String Zip = null;
    public InsertBean() {
    super();
    public String getName() {
    return this.Name;
    public String getAddress() {
    return this.Address;
    public String getZip() {
    return this.Zip;
    public void setName(String pname) {
    this.Name = pname;
    public void setAddress(String paddress) {
    this.Address = paddress;
    public void setZip(String pzip) {
    this.Zip = pzip;
    public void doInsert() throws ClassNotFoundException, SQLException {
    Class.forName("com.mysql.jdbc.Driver").newInstance();//it gives error in this line
    dbCon = DriverManager.getConnection(dbURL,dbuser,dbpass);
    Statement s = dbCon.createStatement();
    String sql = "Insert into Person values ('" + this.Name;
    sql = sql + "', '" + this.Address + "', " + this.Zip;
    sql = sql + ")";
    int insertResult = s.executeUpdate(sql);
    dbCon.close();
    }

    Dear BalusC,
    Thanks for your suggestion. I used try catch block also. But it still gives same error. I have modified my following code. Is there any thing wrong in my code? Please give me your suggestion. Thankyou.
    // Java Document
    package com.webdeveloper.servlets;
    import java.sql.*;
    import java.io.*;
    public class InsertBean {
    private String dbURL = "jdbc:mysql://localhost:3306/test";
    private Connection dbCon;
    private Statement st;
    String dbuser = "root";
    String dbpass = "admin";
    String Name = null;
    String Address = null;
    String Zip = null;
    public InsertBean() {
    super();
    public String getName() {
    return this.Name;
    public String getAddress() {
    return this.Address;
    public String getZip() {
    return this.Zip;
    public void setName(String pname) {
    this.Name = pname;
    public void setAddress(String paddress) {
    this.Address = paddress;
    public void setZip(String pzip) {
    this.Zip = pzip;
    public void doInsert() throws ClassNotFoundException, SQLException {
         try{
         Class.forName("com.mysql.jdbc.Driver").newInstance();
    dbCon = DriverManager.getConnection(dbURL,dbuser,dbpass);
    Statement s = dbCon.createStatement();
    String sql = "Insert into Person values ('" + this.Name;
    sql = sql + "', '" + this.Address + "', " + this.Zip;
    sql = sql + ")";
    int insertResult = s.executeUpdate(sql);
         catch(Exception e){
         System.out.println("error occured :" + e);
         dbCon.close();
    }

  • FileReader - Unreported exception

    Me again!!
    Having problems with FileReader - here's my code:
    void button1_actionPerformed(ActionEvent e)
        FileReader file = new FileReader ("d:\\a.txt");
        BufferedReader inputFile = new BufferedReader(file);
        String input = inputFile.readLine();
        textField1.setText(input);
      }Getting two unreported exception errors - how can I get rid of those?
    NB. java.io.*; is imported...
    Please help!!
    Thanks,
    Sam

    If you look at the API docs, you'll see that many methods throw exceptions. Normally you'll want to use try/catch blocks to deal with exceptions when they occur.
    If you look at the constructor for FileReader, you'll see that is throws a FileNotFoundException. If you look at the readLine() method of class BufferedReader you'll see that it throws an IOException. As FileNotFound is a subclass of IO then you can deal with them both in the same catch block:
    try
        FileReader file = new FileReader ("d:\\a.txt");
        BufferedReader inputFile = new BufferedReader(file);
        String input = inputFile.readLine();
        textField1.setText(input);
    catch(IOException ioex)
        System.out.println(ioex.toString());
    }

  • Unreported exception during connection

    hi all,
    I am trying to connect to the database.I am using
    Class.forName("oracle.jdbc.driver.OracleDriver");
    connection = DriverManager.getConnection(driver+"@"+host+":"+port+":"+serverID,userID,password);
    statement = connection.createStatement();
    but i am getting the following error.
    Error(105,16): unreported exception: java.lang.ClassNotFoundException; must be caught or declared to be thrown
    I tried making the following changes:
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    connection = DriverManager.getConnection(driver+"@"+host+":"+port+":"+serverID,userID,password);
    statement=connection.createStatement();
    but got the following error
    Error(110,55): cannot access class oracle.jdbc.driver.OracleDriver; file oracle\jdbc\driver\OracleDriver.class not found
    I am using the jdevloper9i rc2 and have been working on this project for some time now but didnt got any of the above errors in the different modules of the project when i used any of the above statements,The above errors never occured before.
    Also i did checked my classpath for the classes.jar which was set as
    c:/<jdev direc>/jdbc/lib/classes12.jar
    kindly suggest..
    regards,
    nikhil

    Nikil:
    hi all,
    I am trying to connect to the database.I am using
    Class.forName("oracle.jdbc.driver.OracleDriver");
    connection = DriverManager.getConnection(driver+"@"+host+":"+port+":"+serverID,userID,password);
    statement = connection.createStatement();
    but i am getting the following error.
    Error(105,16): unreported exception: java.lang.ClassNotFoundException; must be caught or declared to be thrownThis is because Class.forName can throw a ClassNotFoundException. Wrap your code with try/catch as in
       try
          Class.forName ...
       catch(Exception ex)
          // exception handling
       }==================
    I tried making the following changes:
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    connection = DriverManager.getConnection(driver+"@"+host+":"+port+":"+serverID,userID,password);
    statement=connection.createStatement();
    but got the following error
    Error(110,55): cannot access class oracle.jdbc.driver.OracleDriver; file oracle\jdbc\driver\OracleDriver.class not found
    I am using the jdevloper9i rc2 and have been working on this project for some time now but didnt got any of the above errors in the different modules of the project when i used any of the above statements,The above errors never occured before.
    Also i did checked my classpath for the classes.jar which was set as
    c:/<jdev direc>/jdbc/lib/classes12.jarLook for classes12.jar on your C drive and set your classpath with the correct file name. The location has changed over time.
    Thanks.
    Sung
    kindly suggest..
    regards,
    nikhil

  • Unreport exception in file upload

    Hi all,
    in jsp
    DiskFileUpload fu = new DiskFileUpload();
    List fileItems = fu.parseRequest(request);
    why want I move then to servlet , I get unreport exception, why?
    Thank you

    You should not rephrase errors. You should know that better after hanging around here that long time.
    Copypaste the actual exception type, message and stacktrace.

  • Why there's error stating "unreported exception" when call function

         public void actionPerformed(ActionEvent evt)
              Object obj = evt.getSource();
              if (obj == DeleteButton)
                   readfile(); // Error here
                   deletefile();
                   rename();
    ========================================================================
         public void readfile() throws Exception
              BufferedReader in = new BufferedReader(new FileReader("WhiteCollar2.txt"));
              line=in.readLine();
              found=0;
              while (line!=null)
                   if ((line.substring(0,6)).equals((String)textfield.getText()))
                        System.out.println("CORRECT\n");
                        found=1;
                   else
                        writefile();                    
                   line=in.readLine();
    ========================================================================
    How come when I call the above readfile(), it gives me :
    DeleteScreen.java:70: unreported exception java.lang.Exception; must be caught or declared to be thrown
    readfile();
    However if I change to the following :
    try{readfile()};
    catch (Exception e) {}
    The code works fine. I am still figuring out on throwing exceptions etc. But how come I already throw exceptions it still complains exception not declared?
    Thanks and Rgds

    but the writefile() function which I called in the
    read() also throw exception but how come I do not need
    to catch it for the write()?The error message says it all: must be caught or declared to be thrown. Thus, you must either catch the exception using try-catch or you must declare that your method throws the exception using the throws declaration.
    Your call to writefile() is in the method readfile() that already declares that it throws Exception. So there is no problem there.
    BTW, you should know that it is generally ill-advised to catch or declare exception using the superclass Exception. You should use as specific an exception class as possible. In this case I suppose it would be IOException.

  • Unreported exception java.sql.SQLException; must be caught or declared to b

    I dont know much about java Please help.
    I have created following class
    import java.sql.*;
    public class Updatedb{
         private String cofeename ;
         private int supid;
         public void getfields(String COFNAM , int SUP_ID){
              cofeename = COFNAM;
              supid = SUP_ID;
         public void indb()
         throws SQLException {
              Connection con = null;
    PreparedStatement pstmt = null;
         try {
         con = DriverManager.getConnection("jdbc:odbc:myDataSource");
         pstmt = con.prepareStatement(
    "UPDATE COFFEES SET SUP_ID = " + supid + "WHERE COF_NAME =" + cofeename );
    //pstmt.setInt(1, SUP_ID);
    //pstmt.setInt(2, COFNAM);
    pstmt.executeUpdate();
    finally {
    if (pstmt != null) pstmt.close();
    Now I am calling above class when button is clicked
    private void UPDATEActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_UPDATEActionPerformed
    // TODO add your handling code here:
    String input = INPUTFIELD.getText();
    Updatedb updateclass = new Updatedb();
    updateclass.getfields(input , 20);
    updateclass.indb( );
    INPUTFIELD.setText( "" );
    I am getting above error. Please help me to solve it.
    Thanks in advance

    A word of honest advice: If you don't understand much of Java, and specifically, if you don't understand how checked exceptions work, you're in over your head looking at JDBC. Step away from it for now, and learn the basics a bit better. Seriously, if you soldier on this way, you'll never really understand what you're doing

  • ERROR:Unreportted Exception java.io.IOEcxeption

    import java.io.*;
    public class MyFileWriter{
         BufferedReader br;
         InputStreamReader isr;
         PrintWriter pw;
         FileWriter fw;
         File f;
         String data;
    public MyFileWriter(){
         isr=new InputStreamReader(System.in);
         br=new BufferedReader(isr);
         f=new File("one.txt");
         fw=new FileWriter(f);
         pw=new PrintWriter(fw);
         readData();
    public void readData(){
         try{
         while(true){
         System.out.println("enter the data except #");
         data=br.readLine();
         if(data.equals("#"))
         break;
         writeData();
    catch(IOException ie){
         System.out.println(ie);
    public void writeData(){
         try{
         pw.println(data);
         *}catch(IOException ie){*
         System.out.println(ie);
         public static void main(String []args){
         MyFileWriter mfw=new MyFileWriter();

    fw=new FileWriter(f);This might throw an IOException so better you write this in to try catch block or report the method that it might throw exception
    This can be done as
         public MyFileWriter() throws IOException
              isr=new InputStreamReader(System.in);
              br=new BufferedReader(isr);
              f=new File("one.txt");
              fw=new FileWriter(f);
              pw=new PrintWriter(fw);
              readData();
         }or by
         public MyFileWriter()
              try
                   isr=new InputStreamReader(System.in);
                   br=new BufferedReader(isr);
                   f=new File("one.txt");
                   fw=new FileWriter(f);
                   pw=new PrintWriter(fw);
                   readData();
              } catch(IOException ioe)
                            System.out.println("Any thing here");
         }And go according to your requirement
    Now for this code
         public void writeData()
              try
                   pw.println(data);
              } catch(IOException ie)
                   System.out.println(ie);
         }here pw.println() method doesnot throws any type of exception particularly IOException
    So thats why you are getting this error
    exception java.io.IOException is never thrown in body of corresponding try statement
                    } catch(IOException ie)so either remove "IOException ie" from there or use only "Exception e"
    Hope this might help you
    Better you refer java docs while coding.

  • Unreported Exception error message

    ( Error message:
    AddStudentException must be caught or declared to be thrown)
    Can anyone explain the error message above from this code?
    public class Course
    public void addStudent(Student s) throws AddStudentException
    public static void main(String[] stringArray)
    Course c1 = new Course("CS110",3);
    Student s1 = new Student("Dave");
    CourseAlreadyPassedException message =
    new CourseAlreadyPassedException
    ("This course has already been taken. ");
    c1.addStudent(s5);
    public abstract class AddStudentException extends Exception {
    // Constructors
    public AddStudentException() { }
    public AddStudentException(String message)
    super (message);
    public class CourseAlreadyPassedException extends AddStudentException {
    // Constructors
    public CourseAlreadyPassedException() { }
    public CourseAlreadyPassedException(String message)
    super (message);

    You've declared that a call to addStudent may throw an AddStudentException. So the caller (the main() method in this case) must either:
    A) handle the exception via try/catch blocks
    try {
    ... call the method here ...
    catch (AddStudentException e) {
    ... do something about the exception here
    or
    B) declare that it also throws the exception
    public static void main(...) throws AddStudentException

Maybe you are looking for

  • Which av cable do I use to hook up my ipod nano 3g to my stereo?

    Do I use the composite or component? Help!

  • How to deactivate part appriser//PMS processess

    Hi experts, I am unable to complete entire pms process. Im struck at end of mid year rating process. In our system there is no concept of part appriser. But some how system is showing the part appriser button as push button. I can t able to save or c

  • Journal Import EBS R12 Issue

    Hi All, Environment : - Solaris 11 - EBS R12 - Oracle DB 11.2.0.3.0 Journal Import Profile option is default (still no settings / default settings / not still tune). Our Journal Import could not submit more than 4000 records. When we try to import da

  • HSI connection dropping, either DSL down or PPPoE unavailabl​e, 10-15 times a day

    Located in Powhatan VA, 23139  Westell 7500 modem, and the modem is configured with PPPoE credentials.  Starting around 10am, the DSL connection regularly drops for most of the morning until about 2-3pm.  Seems tolerable the rest of the day.    Once

  • Additional attributes in F4 Help

    Hi all, For a certain InfoObject we want to add an attribute in the F4-search help. Besides the Key and Description also this attribute appears when the user activates the F4-button on the selection-screen. We activated this attribute for F4-search i