JDBC-Gurus, please comment

"Schörk, Andreas" andreas.schoerk at infor.de
Fri Sep 14 03:23:09 EDT 2001


Hello,
could anybody put some effort into looking through the junit code below and
tell me 
whether this is ok, I am also interested in experiences, how you think that
other
mssql-jdbc-drivers are handling this:

Andreas

first Antons Proc:

    stmt.executeUpdate(" create procedure spTestExec2 as " +
                    "select 'Did it work?' as Result");
    stmt.executeUpdate("create procedure spTestExec as " +
                "set nocount off " + 
		"create table #tmp ( Result varchar(50) ) " + 
		"insert #tmp execute spTestExec2 " +
		"select * from #tmp");
    CallableStatement cstmt = con.prepareCall("spTestExec");
    assertTrue(!cstmt.execute());
    assertTrue(cstmt.getUpdateCount() == 0);  // set 
    assertTrue(!cstmt.getMoreResults());
    assertTrue(cstmt.getUpdateCount() == 0);  // create
    assertTrue(!cstmt.getMoreResults());
    assertTrue(cstmt.getUpdateCount() == 0);  // execute
    assertTrue(!cstmt.getMoreResults());
    assertTrue(cstmt.getUpdateCount() == 1);  // insert
    assertTrue(cstmt.getMoreResults());        
    ResultSet rs = cstmt.getResultSet();
    while (rs.next()) {
      passed = true;
    }
    assertTrue(!cstmt.getMoreResults() && cstmt.getUpdateCount() == -1);


Now some coming from a twisted mind:

    String sqlwithcount2 =
      "create procedure multi1withcount as " +
      "  set nocount off " +
      "  select 'a' " +
      "  select 'b' " +
      "  create table #multi1withcountt (A VARCHAR(20)) " +
      "  insert into #multi1withcountt VALUES ('a') " +
      "  insert into #multi1withcountt VALUES ('a') " +
      "  insert into #multi1withcountt VALUES ('a') " +
      "  select 'a' " +
      "  select 'b' ";
    stmt.executeUpdate(sqlnocount2);

    CallableStatement cstmt = con.prepareCall("exec multi1nocount");
    ResultSet rs = cstmt.executeQuery();
    Statement s2 = cstmt;    
    assertTrue(rs.next());
    assertTrue(rs.getString(1).equals("a"));
    assertTrue(!rs.next());
    assertTrue(s2.getMoreResults());
    rs = s2.getResultSet();
    assertTrue(rs.next());
    assertTrue(rs.getString(1).equals("b"));
    assertTrue(!rs.next());
    assertTrue(s2.getMoreResults());
    rs = s2.getResultSet();
    assertTrue(rs.next());
    assertTrue(!rs.next());
    assertTrue(s2.getMoreResults());
    rs = s2.getResultSet();
    assertTrue(rs.next());
    assertTrue(!rs.next());
    assertTrue(!s2.getMoreResults() && s2.getUpdateCount() == -1);





More information about the FreeTDS mailing list