Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Other Development Tools
 JDBC question

Author  Topic 

Andraax
Aged Yak Warrior

790 Posts

Posted - 2004-03-11 : 07:29:32
Hi!

I'm having a bit of a problem with JDBC calls to SQL Server. I'm using the MS driver SP2. The problem is that some errors from the SQL Server does not cause an SQLException to be thrown, for example division by zero. Other errors work fine, an exception is thrown and can be handled. I have also tried with the BEA Weblogic SQL Server JDBC driver, with the same results.

Does anyone know anything about this?

/Andraax

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-03-11 : 13:09:30
In order for the divide by zero to throw an exception, ANSI_WARNINGS must be turned on. Your connection must have it turned off. Add the option to the connection string.

Tara
Go to Top of Page

Andraax
Aged Yak Warrior

790 Posts

Posted - 2004-03-11 : 16:50:28
Hi Tara and thanks for the reply!

I thought that might be the case, so I checked it out myself. ANSI_WARNINGS are on, so that's not it. And there are no other strange settings on the connection. Other errors work fine, and also when I do RAISERROR myself. I can also see warnings such as null value eliminated etc by checking a warnings property on the connection object.

I will place the question on the MSDN managed newsgroups tomorrow, to see if they have a solution.

/Andraax
Go to Top of Page

Andraax
Aged Yak Warrior

790 Posts

Posted - 2004-03-19 : 02:01:36
OK, I'll post a follow-up here in case someone else is interested or does a search for something like this.

The problem was that different types of errors are handled in different ways. A "select 1/0" statement could be the second statement of the batch, with the first one correct, and will therefore only generate an error when doing the actual fetch of the value.

I think it would be more logical to have the exception thrown when executing the getResultSet() method, but it's not thrown until you execute the rs.next() method for the first time.

Go to Top of Page
   

- Advertisement -