Results 1 to 3 of 3
  1. #1
    mashinata is offline Member
    Join Date
    Feb 2010
    Posts
    1
    Rep Power
    0

    Question Catch raiserror via java

    i have procedure

    create procedure sp_raiserrorSample()
    begin
    declare num integer;
    set num=1;
    if num = 1 then
    raiserror 99999 'I raised this error';
    end if;

    set num=2;
    if num = 2 then
    //execute code
    end if;
    end;


    I call procedure from java via this method:

    public void sampleCode() throws SQLException, ClassNotFoundException
    {
    java.sql.ResultSet rs = null;
    Connection _con = null;

    try
    {
    //create connection

    Class.forName("com.sybase.jdbc2.jdbc.SybDriver");

    String url = String.format("jdbc:sybase:Tds:%s:%s", "xxx.xxx.xxx.xxx","xxxx");

    Properties prop= new Properties();
    prop.setProperty("user","xxxxx");
    prop.setProperty("password","xxxxx");
    prop.setProperty("ServiceName","xxxxx");

    _con = DriverManager.getConnection(url, prop);
    _con.setAutoCommit(false);



    //after connection is created

    CallableStatement cst = _con.prepareCall("{call sp_raiserrorSample()}");
    rs = cst.executeQuery();
    while(rs.next())
    {
    System.out.println(" in while ");
    }

    if (rs != null)
    rs.close();

    }
    catch (SQLException ex)
    {
    System.err.println("ERROR:"+ex.getMessage());
    }
    catch (Exception ex)
    {
    System.err.println("ERROR:"+ex.getMessage());
    }
    finally
    {
    if(_con != null)
    _con.close();
    }
    }//end sampleCode()




    Problem is: when execute
    raiserror 99999 'I raised this error';
    , executing of procedure continue.
    When execute
    set num=2;
    if num = 2 then
    //execute code
    end if;

    after that I get raiserror .
    How to stop executing of procedure when is execute raiserror 99999 'I raised this error';


    When set option continue_after_raierror = off
    result is equal;

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    International crossposting day or something.
    Java Database Connectivity (JDBC) - Catch raiserror via java
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    The problem is in your stored procedure. Look at the database manager documentation. This has nothing to do with Java.

Similar Threads

  1. try catch help
    By vividcooper in forum New To Java
    Replies: 8
    Last Post: 02-11-2010, 10:00 AM
  2. how to catch two exceptions in one catch()?
    By arnab321 in forum New To Java
    Replies: 1
    Last Post: 11-06-2008, 11:54 AM
  3. try catch...
    By MarkWilson in forum New To Java
    Replies: 8
    Last Post: 06-27-2008, 06:39 PM
  4. try catch!?
    By Joe2003 in forum Advanced Java
    Replies: 2
    Last Post: 01-28-2008, 08:51 PM
  5. when to use try...catch
    By javaplus in forum New To Java
    Replies: 2
    Last Post: 11-18-2007, 09:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •