Solved

Java/jtds/MS SQL Server 7

Posted on 2004-10-12
3
1,107 Views
Last Modified: 2012-06-21
Hi,

Have a problem in using open-source jtds jdbc drivers to call a stored procedure on MS SQL Server 7.
I am able to connect to the MS SQL Server and able to execute the callablestatement but
the resultset is always empty.


<-- code snippets -->
String url = "jdbc:jtds:sqlserver://<ip address masked>:1433/<db name>;TDS=7.0";
CallableStatement cs = cnn.prepareCall("{call sp_myprocedure(?)}");
cs.setInt(1,74009436);
cs.execute();

for (;;) {
        int updateCount = cs.getUpdateCount();
        if (updateCount >= 0) {
            // report update count ...
                System.out.println("update count " + updateCount);
        }
        else {
            ResultSet rs = cs.getResultSet();
            if (rs == null)
                break;
            // process resultset ....
ResultSetMetaData rsmd = rs.getMetaData();
int colCount           = rsmd.getColumnCount();

// able to get the metadata
System.out.println("col count "+colCount);
System.out.println(rsmd.getColumnName(1));
System.out.println(rsmd.getColumnName(2));
System.out.println(rsmd.getColumnTypeName(1));
System.out.println(rsmd.getColumnTypeName(2));

// problem here.. as the resultset is alway empty.
// ApplStatus is my status return.
        System.out.println(rs.getObject("ApplStatus"));

        }
        cs.getMoreResults();
    }

<-- end code snippets -->

output :
col count 2
ApplStatus
EntryDate
nvarchar
datetime
java.sql.SQLException: No current row in the ResultSet.
        at net.sourceforge.jtds.jdbc.JtdsResultSet.getColumn(JtdsResultSet.java:258)
        at net.sourceforge.jtds.jdbc.JtdsResultSet.getObject(JtdsResultSet.java:799)
        at net.sourceforge.jtds.jdbc.JtdsResultSet.getObject(JtdsResultSet.java:1143)
        at aut.main(aut.java:76)


any ideas ?

Regards,
denshir.
0
Comment
Question by:denshir
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 200 total points
ID: 12285301
You are not calling next()

while (rs.next()) {
    // get objects
}
0
 

Author Comment

by:denshir
ID: 12285347
Cool ! Silly programming mistake !
Thanks.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12285349
No problem. Easily done ;-)
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question