Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Java/jtds/MS SQL Server 7

Posted on 2004-10-12
3
Medium Priority
?
1,128 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 800 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

609 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