Results 1 to 3 of 3
Thread: Catch raiserror via java
- 02-16-2010, 12:58 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 1
- Rep Power
- 0
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;
- 02-16-2010, 01:05 PM #2
International crossposting day or something.
Java Database Connectivity (JDBC) - Catch raiserror via javaMath problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 02-19-2010, 03:08 AM #3
Similar Threads
-
try catch help
By vividcooper in forum New To JavaReplies: 8Last Post: 02-11-2010, 09:00 AM -
how to catch two exceptions in one catch()?
By arnab321 in forum New To JavaReplies: 1Last Post: 11-06-2008, 10:54 AM -
try catch...
By MarkWilson in forum New To JavaReplies: 8Last Post: 06-27-2008, 05:39 PM -
try catch!?
By Joe2003 in forum Advanced JavaReplies: 2Last Post: 01-28-2008, 07:51 PM -
when to use try...catch
By javaplus in forum New To JavaReplies: 2Last Post: 11-18-2007, 08:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks