Solved

Java/jtds/MS SQL Server 7

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 104
print map entry 34 72
Unhandled exception type Exception 18 42
Crystal Reports Licensing Questions 4 34
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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:
The viewer will learn how to implement Singleton Design Pattern in Java.

860 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