Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS SQL 2000 JDBC driver

Status
Not open for further replies.

Rajeswari

Technical User
Oct 6, 2001
17
0
0
IN
Hello,

I am using the MS SQL 2000 JDBC driver from microsoft to connect to a SQL2000 DB. The connections work fine but when I try to call a stored procedure which has OUTPUT parameters I get an exception. Here is the code snippet:

CallableStatement stmt = con.prepareCall("{(call mysp(?))}");
stmt.registerOutParameter(1, java.sql.Types.INTEGER);
ResultSet rs = stmt.executeQuery();
int out = stmt.getInt(1);

Here in the last line I get an "The requested data is not available" exception.

Any suggestions ?

Thanks !

 
Hi !!

I've solved the problem with OUT parameters :p !! This seems to be a problem with the ODBC stack of Microsoft !! Problem does not arise with other drivers !! This problem arises not only with the ODBC-JDBC driver but with apps like Visual Basic, VC++, etc with use MS ODBC stack !!

The solution:

Do not return Resultsets with OUTPUT parameters !! This does not work. The solution is to split the stored procedures into two procedures, one returning the OUTPUT parameter (if required) and another returning the resultset. Another workaround would be to include the OUTPUT parameter as another Column in the Resultset !! MS ODBC, JDBC client drivers do NOT allow you to return OUTPUT parameters with resultsets !! If you return either one of them alone no problem comes !!

Hope this helps you people out there facing the same problem ;)

- Rajeswari
 
Hi:

I am also trying to use the MS JDBC driver and am getting an exception with error message being the driver itself "com.microsoft.jdbc.sqlserver.SQLServerDriver"

Here is the code I use to simply try and install the driver

// Establish a connection to a SQL database using JDBC.
import java.sql.*;
import javax.sql.*;
import javax.naming.*;

class testconnect {

public static void main (String[] args) {
try {

// Step 1: Load the JDBC driver.
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

// Step 2: Establish the connection to the database.
//String url = "jdbc:microsoft:sqlserver://EAC";
//Connection conn = DriverManager.getConnection
//("jdbc:microsoft:sqlserver://server:1433;User=uid;Password=password");
//ResultSet rs = stmt.executeQuery("SELECT * FROM Categories");

} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
}
Any help would be appreciated. I have set my class path to the 3 jar files MS tells me to Joseph Logan
jlogan@emedrecovery.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top