aspose file tools*
The moose likes JDBC and the fly likes SQL Server 2000 JDBC Driver Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply locked New topic
Author

SQL Server 2000 JDBC Driver Error

Ruchi Verma
Greenhorn

Joined: Mar 28, 2002
Posts: 9
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 ]
Mayank C
Greenhorn

Joined: Jul 18, 2002
Posts: 7
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
Ruchi Verma
Greenhorn

Joined: Mar 28, 2002
Posts: 9
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
Mayank C
Greenhorn

Joined: Jul 18, 2002
Posts: 7
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
Mayank C
Greenhorn

Joined: Jul 18, 2002
Posts: 7
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
Ruchi Verma
Greenhorn

Joined: Mar 28, 2002
Posts: 9
Thanks Mayank,
The program works for me. My installation for SQL Server was not fine.
Thanks again for the help
Abhishek Dharwadkar
Ranch Hand

Joined: Aug 02, 2006
Posts: 44
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,


"I may not have gone where I intended to go, but I think I have ended up where I needed to be"<br /> <br />"He felt that his whole life was some kind of dream and he sometimes wondered whose it was and whether they were enjoying it"<br /> <br />--by Douglas Adams<br /> <br />[SCJP - 96%, SCWCD - 88%, SCBCD - May 2008]
subhash murthy
Greenhorn

Joined: Dec 05, 2006
Posts: 1
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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Rather than resurrecting a topic that was started many years ago, pleae start a new topic describing your issues.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL Server 2000 JDBC Driver Error