RE: JDBC and handling of errors

From: Yuan Shao (v-yshao_at_online.microsoft.com)
Date: 03/17/04


Date: Wed, 17 Mar 2004 03:28:04 GMT

Hi Kalle,

If I understand correctly you are working in a project which uses JDBC to
connect to an SQL Server and execute some stored procedures. However, some
SQLException cannot be thrown in the Java program. Based on my research,
this behavior seems like a problem in our MS SQL Server 2000 Driver for
JDBC driver. Currently, I am checking with our developers and I will post
my response at soon as I have update for you. The tests on my side are
below:

I created a stored procedure named "test" in the pubs database as below and
performed some testing with JDK 1.4.
   CREATE PROCEDURE test AS
       SELECT 1/0
   GO

If I use our MS SQL Server 2000 Driver for JDBC driver (sp2) as below, the
exception is not thrown:
      Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
      Connection conn =
DriverManager.getConnection("jdbc:microsoft:sqlserver://servername:1433;User
=sa;Password=123456789;DatabaseName=pubs");
      Statement statement = conn.createStatement();
      statement.execute("exec test");

However, if I change to use the JDBC for ODBC driver, the exception is
thrown correctly:
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      Connection conn =
DriverManager.getConnection("jdbc:odbc:pubs","sa","123456789");
      Statement statement = conn.createStatement();
      statement.execute("exec test");

I also tested the third party driver [aveConnect 3.0 JDBC Driver for MS SQL
Server] downloaded from http://www.atinav.com/download.htm, and the
exception is also thrown correctly:
      Class.forName("net.avenir.jdbc3.Driver");
      Connection conn =
DriverManager.getConnection("jdbc:AvenirDriver://zyx2k05:1433/pubs;uid=sa;pw
d=123456789");
      Statement statement = conn.createStatement();
      statement.execute("exec test");

In addition, because this problem is mostly related the JDBC driver, if you
would, please post this question in the
microsoft.public.sqlserver.jdbcdriver newsgroup in the future. The
jdbcdriver newsgroup is primarily for issues involving JDBC Driver. The
reason why we recommend posting appropriately is you will get the most
qualified pool of respondents, and other partners who read the newsgroups
regularly can either share their knowledge or learn from your interaction
with us.

Regards,

Michael Shao
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.



Relevant Pages

  • Re: FREETEXTTABLE returns no result for a complex freetext only on JDB
    ... The SQL Server 2000 JDBC driver isn't supported against SQL Server 2005. ... > vacant lot where their employee welfare facilities which had given way ...
    (microsoft.public.sqlserver.jdbcdriver)
  • RE: slow connections with jdbc driver and no entry in hosts file
    ... slow connections with jdbc driver and no entry in hosts file ...
    (microsoft.public.sqlserver.jdbcdriver)
  • Re: jdbc help:sun.jdbc.odbc.JdbcOdbcDriver
    ... > * I have just started JDBC in java. ... The interfaces in java.sql.* are implemented by the provider of the JDBC driver (which ... The provider may be Sun ... ...
    (comp.lang.java.help)
  • RE: MS JDBC Rowset size doubled ?
    ... | I'm a SQL Server DBA, doing some profiling and tuning on a SQL Server ... | database that is being accessed by a JDBC Driver. ... | This is a MS JDBC Driver, running under IBM Websphere access SQL ... | The developers claim they are not adding the asterisk and that SQL ...
    (microsoft.public.sqlserver.jdbcdriver)
  • Re: jdbc help:sun.jdbc.odbc.JdbcOdbcDriver
    ... > * I have just started JDBC in java. ... The interfaces in java.sql.* are implemented by the provider of the JDBC driver (which ... The provider may be Sun ... ...
    (comp.lang.java.programmer)

Loading