File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Problems regarding MS JDBC Driver and JTDS-JDBC Connectivity for MS SQL Server 2000 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Problems regarding MS JDBC Driver and JTDS-JDBC Connectivity for MS SQL Server 2000" Watch "Problems regarding MS JDBC Driver and JTDS-JDBC Connectivity for MS SQL Server 2000" New topic
Author

Problems regarding MS JDBC Driver and JTDS-JDBC Connectivity for MS SQL Server 2000

ajit kumar Verma
Greenhorn

Joined: Jul 11, 2008
Posts: 3
Hi everyone,
I am new here.

Until now I was using mysql server and it was very easy to provide database connectivity; but recently I installed Microsoft SQL Server 2000 and I am facing lots of problems regarding JDBC.

Problem with Microsoft SQL Server 2000 driver for JDBC:

I downloaded and installed �Microsoft SQL Server 2000 driver for JDBC� from Microsoft website and followed the instructions regarding setting ClassPath Variable as follows:

1. Go to Start>Control Panel> System> Environment Variables.
2. Edit Class Path Variable to �.;c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar �
3. Compile and run test program. (Java test program was given on microsoft site.)

When I compiled and run the program; I was getting NoClassDefFoundException i.e JVM was unable to locate & load the Driver. I tried to register the driver and tried again but I was not successful.

Problem with JTDS JDBC driver:

Since I was not successful with Microsoft SQL Server 2000 driver; thus I decided to downloaded zip file jtds 1.2.2 from SourceForge.com. Then I :

1.Made a folder with name jtds-1.2.2 in C:\program files\
2.And then; copied all the content of zip file to jtds1.2.2 folder
3.I edited the classPath Variable to: ;C:\program files\jtsd1.2.2 \jtsd-1.2.2.jar
4.then I compiled run the test program using jdk1.5 (code for program is given in the end)
5. I got these Exceptions :
***********************************************************************
java.sql.SQLException: Network error IOException: Connection refused: connect
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java
:385)
at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java
:50)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:182)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at DB.dbConnect(testConnection.java:28)

at testConnection.main(testConnection.java:13)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:364)
at java.net.Socket.connect(Socket.java:507)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSoc
ket.java:304)
at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:255)
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java
:310)
... 6 more
*****************************************************************

The code testConnection is:

import java.sql.*;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
public class testConnection
{
public static void main(String[] args)
{
DB db = new DB();
db.dbConnect(
"jdbc:jtds:sqlserver://localhost:1433/tempdb","sa","");
}
}

class DB
{
public DB() {}

public void dbConnect(String db_connect_string, String db_userid, String db_password)
{
try
{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection conn = DriverManager.getConnection(
db_connect_string, db_userid, db_password);
System.out.println("connected");

}
catch (Exception e)
{
e.printStackTrace();
}
}
};

i used my user name "sa" and password i gave during Installation of MS SQL Server 2000
What would be the cause of problem with both drivers?

I am definitely making some huge mistakes with java code or jar files Please help me.

Thank you
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10067
    
163

Caused by: java.net.ConnectException: Connection refused: connect


Are you sure the database server is up and running at localhost:1433? What does the following command return?



[My Blog] [JavaRanch Journal]
ajit kumar Verma
Greenhorn

Joined: Jul 11, 2008
Posts: 3
THANK YOU for replying Jaikiran Pai.

On Running command : > telnet localhost 1433
I got this output: Connection to localhost�Could not open connection to the host, on port 1433: connect failed

But MS SQL Server on my machine is running; clicking icon (MS Server) on the task bar it displays green play (> sign. I got both mysql and MS SQL Server 2000 installed on my machine; could that be the problem. Can you have two servers installed on single machine? I got some important databases on mysql server! (i am using Windows Xp)

Thank you
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10067
    
163

Originally posted by ajit kumar Verma:


On Running command : > telnet localhost 1433
I got this output: Connection to localhost�Could not open connection to the host, on port 1433: connect failed


This means that the server is not running on port 1433. Maybe its on some other port. Try using



This command will show the ports being used by various applications. Look for SQL server related process and the corresponding port it is listening to. Then use that port in the connection URL in your code.


Originally posted by ajit kumar Verma:
I got both mysql and MS SQL Server 2000 installed on my machine; could that be the problem. Can you have two servers installed on single machine?


You can have the multiple servers on the same system. That should not be a problem here.
ajit kumar Verma
Greenhorn

Joined: Jul 11, 2008
Posts: 3
Hi
Thank you for helping me, but I am still stuck with same problem.

I tried netstat command; but it does not list or show port no 1433 which suppose to be default for MS SQL Server 2000. I was not able to locate the SQL server port from the list; but did I try several different ports from the netstat list; none worked! Out put of netstat �ab is shown in the end.

********************************************************
So I change to MS SQL 2000 Driver for JDBC again.

I set Class Path to:
.;c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;C:\WINDOWS\system32\QTJava.zip

(Included all three jar files)
*********************************************************
JDBC Driver Name: com.microsoft.jdbc.sqlserver.SQLServerDriver
URL : �jdbc:microsoft:sqlserver://127.0.0.1:1026;User=sa;Password=�
(I�ve not mentioned the password here)
**********************************************************
Test Code was:
import java.sql.*;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.io.*;

public class test1
{

public static void main(String[] args)
{
try
{ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
Connection conn = DiverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1026;User=sa;Password= ");
}
catch(Exception e)
{System.out.println(e);
e.printStackTrace();
}
}}

On JDK1.5:
I�ve compiled the code> javac test1.java
Run > java test1
Out put was:
*********************************************************************
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establi
hing socket.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Sourc
)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source

at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown So
rce)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown
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:525)
at java.sql.DriverManager.getConnection(DriverManager.java:193)
at test1.main(test1.java:17)

*************************************************************
OutPut for netstat �ab

Active Connections

Proto Local Address Foreign Address State PID
TCP ajit-09a2e2cg34:epmap 0.0.0.0:0 LISTENING 1008
c:\windows\system32\WS2_32.dll
C:\WINDOWS\system32\RPCRT4.dll
c:\windows\system32\rpcss.dll
C:\WINDOWS\system32\svchost.exe
-- unknown component(s) --
[svchost.exe]

TCP ajit-09a2e2cg34:microsoft-ds 0.0.0.0:0 LISTENING
[System]

TCP ajit-09a2e2cg34:1521 0.0.0.0:0 LISTENING 2704
[TNSLSNR.exe]

TCP ajit-09a2e2cg34 ptp 0.0.0.0:0 LISTENING 4
[System]

TCP ajit-09a2e2cg34:2030 0.0.0.0:0 LISTENING 2088
[omtsreco.exe]

TCP ajit-09a2e2cg34:2481 0.0.0.0:0 LISTENING 2704
[TNSLSNR.exe]

TCP ajit-09a2e2cg34:3306 0.0.0.0:0 LISTENING 1832
[mysqld-nt.exe]

TCP ajit-09a2e2cg34:42510 0.0.0.0:0 LISTENING 1976
[InoRpc.exe]

TCP ajit-09a2e2cg34:1031 0.0.0.0:0 LISTENING 3972
[alg.exe]

TCP ajit-09a2e2cg34:1026 localhost:3306 ESTABLISHED 848
[winmysqladmin.exe]

TCP ajit-09a2e2cg34:3306 localhost:1026 ESTABLISHED 1832
[mysqld-nt.exe]

UDP ajit-09a2e2cg34:microsoft-ds *:*
[System]

UDP ajit-09a2e2cg34:l2tp *:* 4
[System]

UDP ajit-09a2e2cg34:4500 *:* 748
[lsass.exe]

UDP ajit-09a2e2cg34:isakmp *:* 748
[lsass.exe]

UDP ajit-09a2e2cg34:1900 *:* 1288
c:\windows\system32\WS2_32.dll
c:\windows\system32\ssdpsrv.dll
C:\WINDOWS\system32\ADVAPI32.dll
C:\WINDOWS\system32\kernel32.dll
[svchost.exe]

UDP ajit-09a2e2cg34:1035 *:* 1048
c:\windows\system32\WS2_32.dll
C:\WINDOWS\System32\iasrad.dll
C:\WINDOWS\system32\iassdo.dll
C:\WINDOWS\System32\iashlpr.dll
C:\WINDOWS\System32\mprddm.dll
c:\windows\system32\mprdim.dll
C:\WINDOWS\System32\svchost.exe
C:\WINDOWS\system32\ADVAPI32.dll
C:\WINDOWS\system32\kernel32.dll
[svchost.exe]

UDP ajit-09a2e2cg34:ntp *:* 1048
c:\windows\system32\WS2_32.dll
c:\windows\system32\w32time.dll
ntdll.dll
-- unknown component(s) --
[svchost.exe]

UDP ajit-09a2e2cg34:1034 *:* 1048
c:\windows\system32\WS2_32.dll
C:\WINDOWS\System32\iasrad.dll
C:\WINDOWS\system32\iassdo.dll
C:\WINDOWS\System32\iashlpr.dll
C:\WINDOWS\System32\mprddm.dll
c:\windows\system32\mprdim.dll
C:\WINDOWS\System32\svchost.exe
C:\WINDOWS\system32\ADVAPI32.dll
C:\WINDOWS\system32\kernel32.dll
[svchost.exe]
*******************************************************************
What am I missing? Any suggestions from you would be greatly appreciated.
Thank You

[ July 14, 2008: Message edited by: ajit kumar Verma ]
Ricardo Fuentes
Greenhorn

Joined: Aug 05, 2008
Posts: 1
Same problem solved with SQL Server SP4 update...
SQL Server not responding to 1433 port after first installation.

...after a couple of days...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Problems regarding MS JDBC Driver and JTDS-JDBC Connectivity for MS SQL Server 2000