Forums Register Login

SQL Server 2000 JDBC Driver Error

+Pie Number of slices to send: Send
Hello All,
I am trying to use Microsoft JDBC driver for SQL Server 2000.
Here is my code
public class Connect{
private java.sql.Connection con = null;
private final String url = "jdbc:microsoft:sqlserver://";
private final String serverName= "localhost";
private final String portNumber = "80";
private final String databaseName= "pubs";
private final String userName = "USERID";
private final String password = "PASSWORD";
// Informs the driver to use server a side-cursor,
// which permits more than one active statement
// on a connection.
private final String selectMethod = "cursor";

// Constructor
public Connect(){}

private String getConnectionUrl(){
return url+serverName+":"+portNumber+";databaseName="+databaseName+";selectMethod="+selectMethod+";";
}

private java.sql.Connection getConnection(){
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password);
if(con!=null) System.out.println("Connection Successful!");
}catch(Exception e){
e.printStackTrace();
System.out.println("Error Trace in getConnection() : " + e.getMessage());
}
return con;
}

/*
Display the driver properties, database details
*/

public void displayDbProperties(){
java.sql.DatabaseMetaData dm = null;
java.sql.ResultSet rs = null;
try{
con= this.getConnection();
if(con!=null){
dm = con.getMetaData();
System.out.println("Driver Information");
System.out.println("\tDriver Name: "+ dm.getDriverName());
System.out.println("\tDriver Version: "+ dm.getDriverVersion ());
System.out.println("\nDatabase Information ");
System.out.println("\tDatabase Name: "+ dm.getDatabaseProductName());
System.out.println("\tDatabase Version: "+ dm.getDatabaseProductVersion());
System.out.println("Avalilable Catalogs ");
rs = dm.getCatalogs();
while(rs.next()){
System.out.println("\tcatalog: "+ rs.getString(1));
}
rs.close();
rs = null;
closeConnection();
}else System.out.println("Error: No active Connection");
}catch(Exception e){
e.printStackTrace();
}
dm=null;
}

private void closeConnection(){
try{
if(con!=null)
con.close();
con=null;
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception
{
Connect myDbTest = new Connect();
myDbTest.displayDbProperties();
}
}


I am able to find the driver and all my jar files are in the classpath.I am getting the error.


java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]End of stream
was detected on a read.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source
)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Sour
ce)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Sou
rce)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown S
ource)
at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:177)
at Connect.getConnection(Connect.java:24)
at Connect.displayDbProperties(Connect.java:41)
at Connect.main(Connect.java:77)
Error Trace in getConnection() : [Microsoft][SQLServer 2000 Driver for JDBC]End
of stream was detected on a read.
Error: No active Connection

Please Help Me!
Thanks

[edit: urgent removed from subject]
[ December 05, 2006: Message edited by: Bear Bibeault ]
+Pie Number of slices to send: Send
Hi ,
In getConnectionUrl() method , you append the USERID and PASSWORD also .
In the getConnection() method , pass the above string only . Don't pass userID and password seperately .
Hope it works .
Mayank
+Pie Number of slices to send: Send
Hello Mayank,
Thanks for the response. I have changed the string as
private String getConnectionUrl(){
return url+serverName+":"+portNumber+";databaseName="+databaseName+";selectMethod="+selectMethod+";User="+userName+";Password="+password+"";
}

private java.sql.Connection getConnection(){
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = java.sql.DriverManager.getConnection(getConnectionUrl());
if(con!=null) System.out.println("Connection Successful!");
}catch(Exception e){
e.printStackTrace();
System.out.println("Error Trace in getConnection() : " + e.getMessage());
}
return con;
}
But I am still getting the same error
Let me know
+Pie Number of slices to send: Send
Hi Ruchi,
There don't seem to be a problem with your code.Maybe , you are not including the correct JAR file . You can verify this .
Also , make sure the driver is registered . Give println() after Class.forName().
Mayank
+Pie Number of slices to send: Send
Hi Ruchi,
I tried your code to connect to Oracle . It works fine . So , there might be JAR file problem or Driver problem .
Check whether you can use the particular Driver . Some method is there in DriverManager Class , you can check it .
Mayank
If you can mail me the jar file , I can check it from here .
mayankc@mascotsystems.com
+Pie Number of slices to send: Send
Thanks Mayank,
The program works for me. My installation for SQL Server was not fine.
Thanks again for the help
+Pie Number of slices to send: Send
Hi,
I am getting the same error. Its not because your instalation was wrong.
Read this:
Also, if possible please explain what it exactly means. CAn someone give a more understandable explaination. Now will try using another driver.
http://www.mcse.ms/archive90-2005-9-1649153.html

Thanks & Regards,
+Pie Number of slices to send: Send
I am also facing the same problem.
It is working fine when both are at the same machine
But creating problem when accessed from diffrent machine from Tomcat 4.1.34.
And there is no firewall installed in between the PCs.

Any guidanace please.
+Pie Number of slices to send: Send
Rather than resurrecting a topic that was started many years ago, pleae start a new topic describing your issues.
Look! I laid an egg! Why does it smell like that? Tiny ad, does this smell weird to you?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


Reply locked
This thread has been viewed 3489 times.
Similar Threads
no active Connection...jdbc newbie
Why cant connect to another computer in lan?
Hi...jdbc..no active Connections issue...
JTDS jdbc driver
SQL Server 2008r2 Connection Failed
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:18:00.