Solved

Java/jtds/MS SQL Server 7

Posted on 2004-10-12
3
1,093 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

785 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