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");
  }

Similar Messages

  • 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: java.sql.SQLException; must be caught or declared to be thrown.

    in a servlet, I have a class like:
    class mydb
    public static Connection conn;
    public static void init() throws SQLException
    // Load the Oracle JDBC driver
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    conn = DriverManager.getConnection ("jdbc:oracle:oci8:@baby", "scott", "tiger");
    public static String getValue() throws SQLException
    String curValue="";
    // Create a Statement
    Statement stmt = conn.createStatement ();
    // Select the ENAME column from the EMP table
    ResultSet rset = stmt.executeQuery ("select ENAME from EMP");
    // Iterate through the result and print the employee names
    if (rset.next ())
    curValue = rset.getString (1);
    // Close the RseultSet
    rset.close();
    // Close the Statement
    stmt.close();
    return(curValue);
    public static void destroy() throws SQLException
    // Close the connection
    conn.close();
    but when it is called, errors "java.sql.SQLException; must be caught or declared to be thrown." encountered, how to solve this problem? please help.

    This is part of the Java language.
    If a method throws an exception, then
    it is telling you that the exception is
    something that you should be aware of.
    If you call a method which throws this exception, then the method must either catch this exception, or you may decide that this exception should be caught by the calling method.
    So, your choices are:
    1. Wrap the method call in a try{...} catch block
    -or-
    2. Change the (calling) method's signature to reflect the fact that this method can cause this exception to be thrown (add a 'throws SQLException' ) at end of signature.
    -John
    null

  • 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.

  • PLEASE HELP - unreported exception java.sql.SQLException

    Basically create a database where Time is a field where its automatic enters date and time so no records need to be entered. and the Amount is when the user clicks on a button that amount is stored..basically how do i insert just the amount field
    heres a snippet of the code..
    CarParkDB db=new CarParkDB();
    db.DBConnection();
    String sql="insert into Stats (Time, Amount)"+
    "values ('"+null+"','"+amount+"')";
    db.s.executeQuery(sql); // executing the sq
    Please kindly help me..thank you

    Dont understand or know what the SQL is. The code is
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String sourceURL =
    "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=CarPark.mdb;";
    Connection CarPark =
    DriverManager.getConnection(sourceURL, "admin", "");
    Statement myStatement = CarPark.createStatement();
    String writeString =
    "insert into Stats(Amount) values("+(payment / 100.0)+")";
    myStatement.executeUpdate(writeString);
    ResultSet results = myStatement.executeQuery
    ("SELECT Amount, Time");
    while (results.next()) {
    System.out.print(results.getString(1) + " ");
    System.out.print(results.getString(2) + " ");
    System.out.println(results.getString(3));
    results.close();
    Error is: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.
    I have two colums in the db - Time & amount. The time is updated, but the amount is not.

  • Exception :java.sql.SQLException: Duplicate entry '1-0' for key 1

    Help me in fixing this error
    Exception :java.sql.SQLException: Duplicate entry '1-0' for key 1
    1>>User_ID is primary key and unique and
    2>>User_ID is also auto Incremented
    3>>User_ID is the First coloumn in the table
    PreparedStatement ps=con.prepareStatement("insert into User(user_name,user_email,user_password) values (?,?,?)");
    ps.setString(1,s11);
    ps.setString(2,s22);
    ps.setString(3,s33);
    int i= ps.executeUpdate();

    A growing trend it appears. Must be some new high school and/or college curriculum regarding moral relativism.

  • Exception java.sql.SQLException: This Connection has either timed out

    I am using JRUN 4 & SQL Server 2000
    and Driver is Type 4 SQL Server 2000.
    Type 4 driver : com.microsoft.jdbc.sqlserver.SQLServerDriver
    I am able to connect & fire the query but while insertion record it gives me this error.
    Exception java.sql.SQLException: This Connection has either timed out
    or been closed, and it has returned to its pool. You must re-acquire the Connect
    ion.
    java.sql.SQLException: This Connection has either timed out or been closed, and
    it has returned to its pool. You must re-acquire the Connection.
    at jrun.sql.JRunConnectionHandle.assertConnectionExists(JRunConnectionHa
    ndle.java:50)
    at jrun.sql.JRunConnectionHandle.rollback(JRunConnectionHandle.java:107)
    at krisolshipping.common.LMaintain.postData(LMaintain.java:563)
    at krisolshipping.securities.SUser.doPost(SUser.java:186)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)
    at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
    at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:
    226)
    at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:
    527)
    at jrun.servlet.http.WebService.invokeRunnable(WebService.java:172)
    at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.j
    ava:451)
    Krisol 03 Exception java.sql.SQLException: This Connection has either timed out
    or been closed, and it has returned to its pool. at jrunx.scheduler.Worke
    rThread.run(WorkerThread.java:66)
    You must re-acquire the Connection.
    java.sql.SQLException: This Connection has either timed out or been closed, and
    it has returned to its pool. You must re-acquire the Connection.

    Did you by any chance close the connection?
    The following appendix in the connection URL is recommended for M$ SQL:
    jdbc:microsoft:sqlserver://mssql:1433;SelectMethod=Cursor

  • Java.sql.SQLException: Must be logged on to server

    Hi,
    I am using JCAPS 512. I have implemented a PreparedStatemetn
    which is used to query an orale table.
    Sometimes while executing the JCAPs Project, i am getting following
    exception when this otd gets executed.
    java.sql.SQLException: Must be logged on to server
    Please let help me in resolving the issue.
    Sometimes not every time i get the error.
    Regards
    Venkatesh.S

    This may be your problem...
    oracle-pf-idle-time (3536) Low Risk
    Profiles found that exceed the allowed resource limit for Idle Time
    Description:
    The Idle Time Resource Usage setting limits the maximum idle time allowed in a session. Idle time is a continuous period of inactive time during a session, expressed in minutes. Long-running queries and other operations are not subject to this limit. Setting an Idle Time Resource Usage limit helps prevent users from leaving applications open when they are away from their desks.
    Platforms Affected:
    Oracle Any version
    Remedy:
    Set the Idle Time Resource Usage limit.
    To set the limit using Oracle Security Manager:
    Select the Profiles folder.
    Select the profile to edit.
    Type the new value in the Idle Time box.
    Alternatively, profiles can be updated by using the following command:
    ALTER PROFILE <profile name> LIMIT IDLE_TIME xx
    Consequences:
    References:
    Standards associated with this entry:
    Reported:
    Date not applicable.

  • Exception: java.sql.SQLException: ORA-00904: "SEQ_NAME": invalid identifier

    Hi everyone,
    we are facing the below issue when trying to schedule a BI report.
    Error Details:
    +oracle.apps.xdo.servlet.scheduler.ProcessingException: Exception [TOPLINK-4002] (Oracle TopLink - 11g Release 1 (11.1.1.0.0) (Build 080319)): oracle.toplink.exceptions.DatabaseException+
    Internal Exception: java.sql.SQLException: ORA-00904: "SEQ_NAME": invalid identifier
    Error Code: 904
    Call: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT 50 WHERE SEQ_NAME = 'JOB_ID_SEQ'+
    Query: DataModifyQuery()
    +     at oracle.apps.xdo.servlet.scheduler.toplink.ToplinkDataHandler.insertJob(ToplinkDataHandler.java:830)+
    +     at oracle.apps.xdo.servlet.ui.scheduler.SchedulerServlet.scheduleJob(SchedulerServlet.java:1896)+
    +     at oracle.apps.xdo.servlet.ui.scheduler.SchedulerServlet.doPost(SchedulerServlet.java:293)+
    +     at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)+
    +     at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)+
    +     at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:64)+
    +     at oracle.apps.xdo.servlet.security.SecurityFilter.doFilter(SecurityFilter.java:94)+
    +     at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:621)+
    +     at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:368)+
    +     at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:866)+
    +     at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:448)+
    +     at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:216)+
    +     at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:117)+
    +     at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:110)+
    +     at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)+
    +     at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)+
    +     at java.lang.Thread.run(Thread.java:595)+
    +Caused by: Exception [TOPLINK-4002] (Oracle TopLink - 11g Release 1 (11.1.1.0.0) (Build 080319)): oracle.toplink.exceptions.DatabaseException+
    Internal Exception: java.sql.SQLException: ORA-00904: "SEQ_NAME": invalid identifier
    Error Code: 904
    Call: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT 50 WHERE SEQ_NAME = 'JOB_ID_SEQ'+
    Query: DataModifyQuery()
    +     at oracle.toplink.exceptions.DatabaseException.sqlException(DatabaseException.java:296)+
    +     at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:724)+
    +     at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:790)+
    +     at oracle.toplink.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:524)+
    +     at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:467)+
    +     at oracle.toplink.internal.sessions.AbstractSession.executeCall(AbstractSession.java:795)+
    +     at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:193)+
    +     at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:179)+
    +     at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeNoSelectCall(DatasourceCallQueryMechanism.java:222)+
    +     at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeNoSelect(DatasourceCallQueryMechanism.java:202)+
    +     at oracle.toplink.queryframework.DataModifyQuery.executeDatabaseQuery(DataModifyQuery.java:55)+
    +     at oracle.toplink.queryframework.DatabaseQuery.execute(DatabaseQuery.java:671)+
    +     at oracle.toplink.internal.sessions.AbstractSession.internalExecuteQuery(AbstractSession.java:2260)+
    +     at oracle.toplink.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1074)+
    +     at oracle.toplink.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1058)+
    +     at oracle.toplink.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1032)+
    +     at oracle.toplink.sequencing.QuerySequence.update(QuerySequence.java:319)+
    +     at oracle.toplink.sequencing.QuerySequence.updateAndSelectSequence(QuerySequence.java:258)+
    +     at oracle.toplink.sequencing.StandardSequence.getGeneratedVector(StandardSequence.java:62)+
    +     at oracle.toplink.sequencing.DefaultSequence.getGeneratedVector(DefaultSequence.java:144)+
    +     at oracle.toplink.sequencing.Sequence.getGeneratedVector(Sequence.java:256)+
    +     at oracle.toplink.internal.sequencing.SequencingManager$Preallocation_Transaction_NoAccessor_State.getNextValue(SequencingManager.java:444)+
    +     at oracle.toplink.internal.sequencing.SequencingManager.getNextValue(SequencingManager.java:873)+
    +     at oracle.toplink.internal.sequencing.ClientSessionSequencing.getNextValue(ClientSessionSequencing.java:75)+
    +     at oracle.toplink.internal.descriptors.ObjectBuilder.assignSequenceNumber(ObjectBuilder.java:234)+
    +     at oracle.toplink.internal.sessions.UnitOfWorkImpl.assignSequenceNumbers(UnitOfWorkImpl.java:419)+
    +     at oracle.toplink.internal.sessions.UnitOfWorkImpl.calculateChanges(UnitOfWorkImpl.java:497)+
    +     at oracle.toplink.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1407)+
    +     at oracle.toplink.internal.sessions.UnitOfWorkImpl.commitRootUnitOfWork(UnitOfWorkImpl.java:1167)+
    +     at oracle.toplink.internal.sessions.UnitOfWorkImpl.commit(UnitOfWorkImpl.java:939)+
    +     at oracle.apps.xdo.servlet.scheduler.toplink.ToplinkDataHandler.insertJob(ToplinkDataHandler.java:815)+
    +     ... 16 more+
    Caused by: java.sql.SQLException: ORA-00904: "SEQ_NAME": invalid identifier
    +     at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:138)+
    +     at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:316)+
    +     at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:282)+
    +     at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:639)+
    +     at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:113)+
    +     at oracle.jdbc.driver.T4CStatement.execute_for_rows(T4CStatement.java:561)+
    +     at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1161)+
    +     at oracle.jdbc.driver.OracleStatement.executeUpdate(OracleStatement.java:1585)+
    +     at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:713)+
    +     ... 45 more+
    Found a thread related to this but there it was explained that the error was occuring when trying to notify regarding output through email. In our case, issue is occuring just during scheduling itslef.
    Also I haved checked the following schedular tables in my database.
    SQL> select table_name from all_tables where table_name like 'S_NQ%'
    +2 /+
    TABLE_NAME
    S_NQ_ERR_MSG
    S_NQ_INSTANCE
    S_NQ_JOB_PARAM
    S_NQ_JOB
    SQL> select SEQ_NAME.CURRVAL FROM DUAL;
    select SEQ_NAME.CURRVAL FROM DUAL
    *+
    ERROR at line 1:
    ORA-02289: sequence does not exist
    Please help me out in solving this as I have tried almost all possible solutions.
    Thanks,
    Sri Harsha.
    Edited by: user10545574 on Dec 20, 2009 10:24 PM

    Hello,
    In the delivery email configuration server page (under BI Publisher Admin Tab), the username / password to enter is the one defined on the email server itself. It is the user that will be user to send the emails when scedhuling a report.
    It may not be Administrator/ Administrator (not a user defined with OBI admin tool) but the username/password defined on the email server itself.
    Moreover, to properly configure the BI Publisher Scheduler, it is a prerequistes to create bipsched user on Oracle DB and install the schema tables in Oracle DB (by clicking on Install Schema button after defining database connection under Admin / Scheduler Configuration tab)
    From the error your are getting 'SEQ_NAME unknown..., it appears that the tables are not created'.
    Hope this helps and good luck
    Matthieu

  • Regarding Internal Exception: java.sql.SQLException

    While deploying the application we are encounter a following error,
    Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: FATAL: sorry, too many clients already
    Error Code: 0
    Deployment error:
    Please give me a suggession for this error.
    Thanks,

    While deploying the application we are encounter a following error,
    Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: FATAL: sorry, too many clients already
    Error Code: 0
    Deployment error:
    Please give me a suggession for this error.
    Thanks,

  • Unexpected exception : java.sql.SQLException

    I tried to execute a query by reading it from the console and passing it as an argument to executeQuery( ) method.
    It is giving the following error message
    Unexpected exception : java.sql.SQLException: [Microsoft][ODBC Microsoft Access
    Driver] Syntax error in FROM clause. , sqlstate = 37000
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in
    FROM clause.
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6031)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6188)
    at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:2494)
    at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:314)
    at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:2
    29)
    at assignment1.main(assignment1.java:63)
    Can anyone help me to get rid of this error.
    Thanks,
    Suma

    It's telling you that the query you read in from the console is not valid SQL, in particular that there is an error somewhere in the FROM clause of the query. To solve this problem, only type valid queries into this program. Or if you can't guarantee that -- and you can't -- report the error to the person typing in the invalid queries.

  • Exception java.sql.SQLException: [Microsoft][ODBC Microsoft Access 97 Drive

    Hi,
    I am writing a simple program wihich will display the list of table for a given database. Currently I am using JDBC-ODBC bridge for accessing MS Acccess data base. When I call getTables method of DatabaseMetaData. Following Exception was thrown. Any clue what could be the reason for this?
    Exception java.sql.SQLException: [Microsoft][ODBC Microsoft Access 97 Driver]Driver not capable
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access 97 Driver]Driver not capable
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6106)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6263)
    at sun.jdbc.odbc.JdbcOdbc.SQLTables(JdbcOdbc.java:4917)
    at sun.jdbc.odbc.JdbcOdbcDatabaseMetaData.getTables(JdbcOdbcDatabaseMetaData.java:2395)
    at test.databaseMetaData.main(databaseMetaData.java:36)
    This exception occured in the following block:
         String[] strTables = {"TABLES"};
    rs = dbmd.getTables( null, "DBIS", "A%", strTables);
    Thanks in advance
    Cheers,
    Krishna

    Hi Krishna,
    First, do you have a correct ODBC setup on the platform your working on -- data source, etc.
    Second, please enclose the Java code for your connection, etc..
    Good luck!
    Francis

  • Internal Exception: java.sql.SQLException: Closed ConnectionError Code: 170

    I have the following situation:
    When accidentaly toplink loose connection with database server for short time and request coming from client in the same time toplink close connection with database server and generate the following exception:
    Exception [TOPLINK-4002] (Oracle TopLink - 10g Developer Preview 3 (10.1.3.0 ) (Build 041116)): oracle.toplink.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: Closed ConnectionError Code: 17008
         at oracle.toplink.exceptions.DatabaseException.sqlException(DatabaseException.java:272)
    Problem is because toplink does not renew the connection with database server. Anybody know how to resolve this situation ?
    Mention:
    Application is build around toplink server session that serve client giving them clientsession and unitofwork.

    Hi
    I am getting this exception randomly, I want my application to be flexible. I am using Glassfish V2.1.1, Toplink Essentials, Windows linux, Oracle 11g database.
    Below is the stacktrace :
    Local Exception Stack:
    Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.1 (Build b31g-fcs (10/19/2009))): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: Closed Connection
    Error Code: 17008
    Call: SELECT t0.CRITICALITY, t0.USER_TAG_IDENT, t0.SEGMENT_GROUP_YN, t0.NAME, t0.GMT_LAST_UPDATED, t0.LONG_DESCRIPTION, t0.CS_TYPE_DB_SITE, t0.CS_TYPE_DB_ID, t0.CS_TYPE_CODE, t0.SEGMENT_SITE, t0.SEGMENT_ID, t0.RSTAT_TYPE_CODE, t0.LAST_UPD_DB_SITE, t0.LAST_UPD_DB_ID, t0.SG_DB_SITE, t0.SG_DB_ID, t0.SG_TYPE_CODE FROM SEGMENT t0, ROW_STATUS_TYPE t2, SEGMENT_TYPE t1 WHERE ((((t0.SEGMENT_ID NOT IN (SELECT t3.CHILD_SG_ID FROM SEGMENT_CHILD t3 WHERE (t3.SEGMENT_SITE = ?)) AND (t0.SEGMENT_SITE = ?)) AND (t1.SG_TYPE_CODE = ?)) AND (t2.RSTAT_TYPE_COD = ?)) AND (((t1.SG_DB_SITE = t0.SG_DB_SITE) AND ((t1.SG_DB_ID = t0.SG_DB_ID) AND (t1.SG_TYPE_CODE = t0.SG_TYPE_CODE))) AND (t2.RSTAT_TYPE_COD = t0.RSTAT_TYPE_CODE))) ORDER BY t0.USER_TAG_IDENT ASC
         bind => [0000000100000001, 0000000100000001, 9, 1]
    Query: ReportQuery(com.esrg.jpa.Segment)
         at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:319)
         at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:566)
         at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:452)
         at oracle.toplink.essentials.threetier.ServerSession.executeCall(ServerSession.java:473)
         at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
         at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:214)
         at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:285)
         at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:615)
         at oracle.toplink.essentials.internal.queryframework.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2416)
         at oracle.toplink.essentials.internal.queryframework.ExpressionQueryMechanism.selectAllReportQueryRows(ExpressionQueryMechanism.java:2382)
         at oracle.toplink.essentials.queryframework.ReportQuery.executeDatabaseQuery(ReportQuery.java:802)
         at oracle.toplink.essentials.queryframework.DatabaseQuery.execute(DatabaseQuery.java:628)
         at oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:692)
         at oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:746)
         at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2244)
         at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:952)
         at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:924)
         at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:367)
         at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.getResultList(EJBQueryImpl.java:478)
         at com.sun.enterprise.util.QueryWrapper.getResultList(QueryWrapper.java:196)
         at com.esrgtech.erm.viewer.segment.eRMViewerSegmentBean.findSystem(eRMViewerSegmentBean.java:537)
         at com.esrgtech.erm.viewer.segment.eRMViewerSegmentBean.getTree(eRMViewerSegmentBean.java:131)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1011)
         at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:175)
         at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2929)
         at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4020)
         at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:197)
         at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:127)
         at $Proxy60.getTree(Unknown Source)
         at com.esrgtech.erm.DataViewerSession.getTree(DataViewerSession.java:237)
         at com.esrgtech.erm.ui.dashboard.DashboardLeft.buildTree(DashboardLeft.java:88)
         at com.esrgtech.erm.ui.dashboard.DashboardLeft.<init>(DashboardLeft.java:48)
         at com.esrgtech.erm.ui.dashboard.Dashboard.createLeftContent(Dashboard.java:55)
         at com.esrgtech.erm.ui.base.WebPageTwoColLeft180.buildPage(WebPageTwoColLeft180.java:58)
         at com.esrgtech.erm.ui.dashboard.Dashboard.<init>(Dashboard.java:34)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
         at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
         at org.apache.wicket.session.DefaultPageFactory.createPage(DefaultPageFactory.java:192)
         at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:57)
         at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:81)
         at com.esrgtech.erm.ui.signin.SignInPanel.onSignInSucceeded(SignInPanel.java:236)
         at com.esrgtech.erm.ui.signin.SignInPanel$SignInForm.onSubmit(SignInPanel.java:116)
         at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1536)
         at org.apache.wicket.markup.html.form.Form.process(Form.java:925)
         at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:887)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
         at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
         at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
         at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
         at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
         at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
         at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
         at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
         at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:312)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:313)
         at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218)
         at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
         at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
         at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
         at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
         at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
         at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1093)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
         at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
         at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1093)
         at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:291)
         at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:666)
         at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:597)
         at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:872)
         at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
         at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
         at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
         at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:264)
         at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
    Caused by: java.sql.SQLException: Closed Connection
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
         at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:840)
         at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:759)
         at com.sun.gjc.spi.base.ConnectionHolder.prepareStatement(ConnectionHolder.java:475)
         at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java:1162)
         at oracle.toplink.essentials.internal.databaseaccess.DatabaseCall.prepareStatement(DatabaseCall.java:612)
         at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:485)
         ... 90 more
    Need Help.....

  • Mailing attachments; java.io.IOException; must be caught or declared to be

    I seem to be having trouble setting up to attach a file and I'm getting the error message
    java.io.IOException; must be caught or declared to be
    //other related code
        String bookingFilename = "what ever filename";
    // create some properties and get the default Session
         Properties props = new Properties();
         props.put("mail.smtp.host", host);
         Session session = Session.getInstance(props, null);
         //session.setDebug(debug);
         try {
             // create a message
             MimeMessage msg = new MimeMessage(session);
             msg.setFrom(new InternetAddress(from));
             InternetAddress[] address = {new InternetAddress(to)};
             msg.setRecipients(Message.RecipientType.TO, address);
             msg.setSubject(subject);
             msg.setSentDate(new Date());
             // create and fill the first message part
             MimeBodyPart mbp1 = new MimeBodyPart();
             mbp1.setText(msgText1);
             // create and fill the second message part
             MimeBodyPart mbp2 = new MimeBodyPart();
                //PROBLEM LINE
                mbp2.setFilename(bookingFilename);
             // create the Multipart and its parts to it
             Multipart mp = new MimeMultipart();
             mp.addBodyPart(mbp1);
             mp.addBodyPart(mbp2);
             // add the Multipart to the message
             msg.setContent(mp);
             // send the message
             Transport.send(msg);
         } catch (MessagingException mex) {
             mex.printStackTrace();
             Exception ex = null;
             if ((ex = mex.getNextException()) != null) {
              ex.printStackTrace();the following is the problem code
    mbp2.setFilename(bookingFilename);am I putting the filename in the wrong format?
    I'm hoping to specify the exact filename using "if" statements so the current
    String bookingFilename = "what ever filename";is just a placeholder
    I'd be very grateful for any assitance
    eventually I intend to email out 3 seperate attachments at the same time,
    from a bank of about 10 files which are either pdf's or word doc's
    Dioxin

    Lets not go into my lack of Java training just yet :-P
         } catch (IOException ioex) {
             ioex.printStackTrace();was the block I was missing
    I'd also miswritten the problem code...cos I'd been fiddling with other commands
    mbp2.attachFile(bookingFilename);well it appears to compile... now to fire off a test email!
    cheers
    Dioxin

  • Conn.rollback() must be caught or declared to be thrown

    Hi, I'm having problems compiling the following code
    private void toInsert(String insert_foo, int insert_bar) {
              InitialContext context = null;
              Connection conn = null;
              PreparedStatement pstmt= null;     
              try {
                   context = new InitialContext();
                   DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/TestDB");
                   conn = ds.getConnection();
                   conn.setAutoCommit(false);
                   pstmt = conn.prepareStatement("INSERT into testdata values(?, ?)");
                   pstmt.setString(1, insert_foo);
                   pstmt.setInt(2, insert_bar);
                   pstmt.executeUpdate();
                   conn.commit();
                   conn.setAutoCommit(true);
                   pstmt.close();
                   pstmt = null;
                   conn.close();
                   conn = null;
                   context.close();
                   context = null;
              catch (Exception e) {
                   conn.rollback();
              finally {
                   if (pstmt != null) {
                        try { pstmt.close(); }          
                        catch (SQLException e) {;}     
                        pstmt = null;               
                   if (conn != null) {
                        try { conn.close(); }          
                        catch (SQLException e) {;}     
                        conn = null;               
                   if (context != null) {
                        try { context.close(); }     
                        catch (NamingException e) {;}     
                        context = null;               
         }I got this error when I try to compile the above;
    unreported exception java.sql.SQLException; must be caught or declared to be thrown
    conn.rollback();
    I search and read through a lot of posts here that rollback() could be used in the catch block but why I can't I compile it?
    Please help me out, thank you.
    puzzled....

    Is it similiar to factory methods? No.
    I've read up on this:
    http://www.javaworld.com/javaworld/javaqa/2001-05/02-qa-0511-factory.html?
    "small boy with a pattern" syndrome strikes again.
    Could you assist to help me in giving me guidelines
    for writing the database utilites class?
    Appreciated...
    public final class DatabaseUtils
        public static void close(Connection c)
            if (c != null)
                try
                    c.close();
                catch (SQLException e)
                      // print stack trace or, better yet, log the exception with Log4J
        // same for other close operations on ResultSet and Statement
        public void rollback(Connection c)
            if (c != null)
                try
                    c.rollback();
                catch (SQLException e)
                      // print stack trace or, better yet, log the exception with Log4J
    }%

Maybe you are looking for

  • How I can create a XML file from java Aplication

    How I can create a XML file from java Aplication whith have a the following structure <users> <user> <login>anyName</login>      <password>xxxx</password> </user> </users> the password label must be encripted accept any suggestion

  • Access regression status field in bugdb

    Hello: We are writing an application to create/edit a bug on Oracle BugDB. We found regression status is a field in RPTHEAD and its values are in table bug_lookups. There are some state logic for that field. When the current value is empty, its drop

  • Unwanted Snap

    I try to move a layer and it snaps back, even though snap has been turned of. I'm only able to move it with my tablet. I have to plug in the tablet just to be able to move the layer.... It's exremely bothersome. Anyone know how to make it stop? It ha

  • ORA-06502: PL/SQL: numeric or value error: Bulk Bind: Truncated Bink

    I have a map which worked fine in 10.2.0.1. The same map in 11.2.0.2 is giving me the error: 'ORA-06502: PL/SQL: numeric or value error: Bulk Bind: Truncated Bink.' I have one source and one target. This is a straight load, no transformations. While

  • Commodity / Import Code Number

    Hello Friends, Is there any way we can enter the Import code number with an enduser transaction. I know there is a provision to enter from SPRO. I am also aware of the method thru VI94, but is there any way we can enter just one Import code with easy