I am trying to connect to sql server for the first time using the sourceforge driver but keept getting the error:ClassNotFoundException. I have set the class path in the system properties (windows 2003) as: Classpath=C:\db\src\db\jtds-1.1.jar;C:\db\build\classes\jtds-1.1.jar.
I have set two classpaths as I am using netbeans which has created the direcotry structures: C:\db\src\ for .Java files and C:\db\build\classes for .class files, I didnt know which directory to place the jar file in so I placed it in both.
I have also tried running the class file and setting the classpath from the command line, however i stil get the same error.
I also read in a previous forum post that the jar file should also be placed in the external lib for the jdk, is this true. I have placed it in C:\jdk\jdk\jre\lib\ext\jtds-1.1.jar, however I still get the same error.
Any help would be greatly appreciated as I don't know what else to try.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When you run your app from the command line use something like:
java -cp C:\db\src\db\jtds-1.1.jar Main
To run it from NetBeans (or any other IDE) there's an IDE specific way of adding jar files to the classpath. I can't help you on that as I have no idea how it's done in NetBeans. And don't place the jar in the lib\ext folder; as you can see it doesn't always work and it may cause other issues.
Alin.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For anyone with similar problem: add a classpath in Netbeans as follows:
right click on project icon in project window (top left) then select properties. in new window select Libraries from 'categories' menu, then select ' compile' tab, then add jar file.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a problem you may know the solution. I use "Neatbeans 5.0" With "Sun Java System Application Server" I have already
1) "add a classpath in Netbeans as follows:
right click on project icon in project window (top left) then select properties. in new window select Libraries from 'categories' menu, then select ' compile' tab, then add jar file. "
2) Put the jtds-1.2.jar in C:\Exercises\NetBeans\AppAskiseis\build\web\WEB-INF\lib
on my PC
That's very much an Eclipse issue (or rather an Eclipse configuration issue). I think you would be better off asking this question on an Eclipse forum rather than here (I'm not using Eclipse, for example, so I'm not familiar with it).
Alin.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a Similar problem: but in my case it is ALMOST Working, but i am getting the exception:
java.sql.SQLException: Network error IOException: Connection refused: connect
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:372)
at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java:50)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:178)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at com.webmethods.jdbc.qa.Connect.getConnection(Connect.java:39)
at com.webmethods.jdbc.qa.Connect.displayDbProperties(Connect.java:58)
at com.webmethods.jdbc.qa.Connect.main(Connect.java:98)Error Trace in getConnection() : Network error IOException: Connection refused: connect
Error: No active Connection
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:366)
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(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:289)
at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:250)
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:297)
... 7 more
My Source code is:
public class Connect {
private java.sql.Connection con = null;
privatefinalStringurl="jdbc:jtds:sqlserver://";privatefinalStringserverName="MyIPAddress";privatefinalStringportNumber="1433";privatefinalStringdatabaseName="test";privatefinalStringuserName="MyUserName";privatefinalStringpassword="MyPassword";//Informsthedrivertouseserveraside-cursor,//whichpermitsmorethanoneactivestatement//onaconnection.privatefinalStringselectMethod="cursor";//ConstructorpublicConnect(){}privateStringgetConnectionUrl(){returnurl+serverName+":"+portNumber+";databaseName="+databaseName+";selectMethod="+selectMethod+";";}privatejava.sql.ConnectiongetConnection(){try{Class.forName("net.sourceforge.jtds.jdbc.Driver");con=java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password);if(con!=null)System.out.println("ConnectionSuccessful!");}catch(Exceptione){e.printStackTrace();System.out.println("ErrorTraceingetConnection():"+e.getMessage());}returncon;}/* * Display the driver properties, database details */publicvoiddisplayDbProperties(){java.sql.DatabaseMetaDatadm=null;java.sql.ResultSetrs=null;try{con=this.getConnection();if(con!=null){dm=con.getMetaData();System.out.println("DriverInformation");System.out.println("\tDriverName:"+dm.getDriverName());System.out.println("\tDriverVersion:"+dm.getDriverVersion());System.out.println("\nDatabaseInformation");System.out.println("\tDatabaseName:"+dm.getDatabaseProductName());System.out.println("\tDatabaseVersion:"+dm.getDatabaseProductVersion());System.out.println("AvalilableCatalogs");rs=dm.getCatalogs();while(rs.next()){System.out.println("\tcatalog:"+rs.getString(1));}rs.close();rs=null;closeConnection();}elseSystem.out.println("Error:NoactiveConnection");}catch(Exceptione){e.printStackTrace();}dm=null;}privatevoidcloseConnection(){try{if(con!=null)con.close();con=null;}catch(Exceptione){e.printStackTrace();}}publicstaticvoidmain(String[]args)throwsException{ConnectmyDbTest=newConnect();myDbTest.displayDbProperties();}
}
Can anyone help me ? i am running in eclipse, and the MSSQL Server is on Windows XP , on my desktop.
Both the MSSQL Server and the JDBC Driver are running on the same machine (My Windows XP Desktop), do i need to do something to allow incoming connections to MSSQL Server ?
Thanks in Advance.
-Kamal.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Please read the FAQ ( http://jtds.sourceforge.net/faq.html ) before asking for help. And don't hijack someone else's thread, start a new one, especially if you have a different problem than the OP.
Alin.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The local instance of SQL Server may only be binding to localhost or 127.0.0.1. Try using 127.0.0.1 instead of the IP address of your XP box to see if that works.
BTW, the selectMethod parameter has NO EFFECT on jTDS. This RFE contains an old patch that has the effect of always enabling cursors at the cost of performance. It probably won't apply cleanly to the source in CVS, though.
I am trying to connect to sql server for the first time using the sourceforge driver but keept getting the error:ClassNotFoundException. I have set the class path in the system properties (windows 2003) as: Classpath=C:\db\src\db\jtds-1.1.jar;C:\db\build\classes\jtds-1.1.jar.
I have set two classpaths as I am using netbeans which has created the direcotry structures: C:\db\src\ for .Java files and C:\db\build\classes for .class files, I didnt know which directory to place the jar file in so I placed it in both.
I have also tried running the class file and setting the classpath from the command line, however i stil get the same error.
Here is the code i have been using:
import java.io.;
import java.net.;
import java.sql.;
import java.util.;
public class Main {
}
I also read in a previous forum post that the jar file should also be placed in the external lib for the jdk, is this true. I have placed it in C:\jdk\jdk\jre\lib\ext\jtds-1.1.jar, however I still get the same error.
Any help would be greatly appreciated as I don't know what else to try.
When you run your app from the command line use something like:
java -cp C:\db\src\db\jtds-1.1.jar Main
To run it from NetBeans (or any other IDE) there's an IDE specific way of adding jar files to the classpath. I can't help you on that as I have no idea how it's done in NetBeans. And don't place the jar in the lib\ext folder; as you can see it doesn't always work and it may cause other issues.
Alin.
Thank you that worked.
For anyone with similar problem: add a classpath in Netbeans as follows:
right click on project icon in project window (top left) then select properties. in new window select Libraries from 'categories' menu, then select ' compile' tab, then add jar file.
I have a problem you may know the solution. I use "Neatbeans 5.0" With "Sun Java System Application Server" I have already
1) "add a classpath in Netbeans as follows:
right click on project icon in project window (top left) then select properties. in new window select Libraries from 'categories' menu, then select ' compile' tab, then add jar file. "
2) Put the jtds-1.2.jar in C:\Exercises\NetBeans\AppAskiseis\build\web\WEB-INF\lib
on my PC
3) I wrote this simple code in JSP
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
<sql:setDataSource
var ="something"
driver="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://192.168.2.221/infoshop"
user="clroot"
password="clroot"
/>
<sql:query var="test" dataSource="something">
SELECT Code FROM Material
</sql:query>
<html>
<head>
<title>SQL Tag Out Examples</title>
</head>
<body>
kostas ole
</body>
</html>
AND I GET the error message
"Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver""
Do I have to do something else?
any ideas why eclipse won't pick up the jTDS.jar even after i added it as an external jar? won't compile, no matter where i place it.
thanks.
That's very much an Eclipse issue (or rather an Eclipse configuration issue). I think you would be better off asking this question on an Eclipse forum rather than here (I'm not using Eclipse, for example, so I'm not familiar with it).
Alin.
Hi,
I have a Similar problem: but in my case it is ALMOST Working, but i am getting the exception:
java.sql.SQLException: Network error IOException: Connection refused: connect
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:372)
at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java:50)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:178)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at com.webmethods.jdbc.qa.Connect.getConnection(Connect.java:39)
at com.webmethods.jdbc.qa.Connect.displayDbProperties(Connect.java:58)
at com.webmethods.jdbc.qa.Connect.main(Connect.java:98)Error Trace in getConnection() : Network error IOException: Connection refused: connect
Error: No active Connection
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:366)
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(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:289)
at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:250)
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:297)
... 7 more
My Source code is:
public class Connect {
private java.sql.Connection con = null;
}
Can anyone help me ? i am running in eclipse, and the MSSQL Server is on Windows XP , on my desktop.
Both the MSSQL Server and the JDBC Driver are running on the same machine (My Windows XP Desktop), do i need to do something to allow incoming connections to MSSQL Server ?
Thanks in Advance.
-Kamal.
Please read the FAQ ( http://jtds.sourceforge.net/faq.html ) before asking for help. And don't hijack someone else's thread, start a new one, especially if you have a different problem than the OP.
Alin.
The local instance of SQL Server may only be binding to localhost or 127.0.0.1. Try using 127.0.0.1 instead of the IP address of your XP box to see if that works.
BTW, the selectMethod parameter has NO EFFECT on jTDS. This RFE contains an old patch that has the effect of always enabling cursors at the cost of performance. It probably won't apply cleanly to the source in CVS, though.
Make jTDS work with IBM WebSphere 4
http://sourceforge.net/tracker/index.php?func=detail&aid=1201617&group_id=33291&atid=407764
Dave