Solved

Java/jtds/MS SQL Server 7

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now