Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ClassNotFoundException

 
Punya Pratap Singh
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new in jdbc.

Code is -


I first downloaded the Jtds.jar and set class path in cmd as--

set classpath = C:\Program Files\SQL server driver\jtds-1.2.5.jar

Also I am using windows authentication.and unable to set Sql server authentication.

It is still throwing Exception please guide me.


 
Campbell Ritchie
Sheriff
Posts: 48645
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ask your computer to echo your classpath. Because there are spaces in it, you may need to surround the classpath in "quotes".
 
Philip Grove
Ranch Hand
Posts: 68
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Ask your computer to echo your classpath. Because there are spaces in it, you may need to surround the classpath in "quotes".


While normally a good theory, the environment variables on my Windows computer (including the classpath) contain spaces and works fine. If you set an environment variable in Windows my experience is that the change does not take effect on the command line before you start a new session.
 
Paul Clapham
Sheriff
Pie
Posts: 20945
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Philip Grove wrote:... the environment variables on my Windows computer (including the classpath) contain spaces and works fine...


That may be true, but that would be because you set it up correctly. The line posted by Punya doesn't do that. It needs quotes.
 
Punya Pratap Singh
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your replies.
As suggested I used quotes this time in setting Class Path,but result is still the same.
Also when I do-

echo %CLASSPATH%
results is - %CLASSPATH%
but is not showing any classpath which has been set.




 
Ashutosh Limaye
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to display classpath the command is without the assignment operator.
 
Punya Pratap Singh
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I use the command then output is as follows ---

C:\>set classpath

CLASSPATH=C:\Program Files\SQL server driver\jtds-1.2.5.jar;

Also I have a question that classpath also been set for java.then why only class path for this particular jar is showing,why not for all set class path's.

Also suggest me ,where am I doing wrong in previous problem.(Connecting to Database).
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also I have a question that classpath also been set for java...

Looking at the out put of CLASSPATH it doesn't. You don't need to set it for Java core libraries.
where am I doing wrong in previous problem.(Connecting to Database).

How you run the program?
 
Punya Pratap Singh
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Code I am using is---

 
Ashutosh Limaye
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Punya Pratap Singh wrote:When I use the command then output is as follows ---

C:\>set classpath

CLASSPATH=C:\Program Files\SQL server driver\jtds-1.2.5.jar;

Also I have a question that classpath also been set for java.then why only class path for this particular jar is showing,why not for all set class path's.

Also suggest me ,where am I doing wrong in previous problem.(Connecting to Database).


Try setting it again as:
set classpath = "C:\Program Files\SQL server driver\jtds-1.2.5.jar";%classpath%


And then check the classpath again.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IMO, using the CLASSPATH environment variables is more trouble than it's worth. Something like this would be preferable:

java -cp "C:\Program Files\SQL server driver\jtds-1.2.5.jar;." Test
 
Ashutosh Limaye
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:IMO, using the CLASSPATH environment variables is more trouble than it's worth. Something like this would be preferable:

java -cp "C:\Program Files\SQL server driver\jtds-1.2.5.jar;." Test


Yep That's a better approach. That will ensure it takes the right path to the jar.
 
Punya Pratap Singh
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf Dittmer,Ashutosh

Now It is able to locate the class but saying that this driver is not appropriate.
As I already mentioned that I am using windows autentication.
Is it not possible to connect to Sql server with windows autentication ??



 
Rob Sang
Greenhorn
Posts: 2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Punya Pratap Singh wrote:Thanks Ulf Dittmer,Ashutosh

Now It is able to locate the class but saying that this driver is not appropriate.
As I already mentioned that I am using windows autentication.
Is it not possible to connect to Sql server with windows autentication ??





The URL you've used indicates the Microsoft proprietary SQLServer JDBC driver. To use JTDS you need

 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch, Rob Sang!
 
Rob Sang
Greenhorn
Posts: 2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vijitha Kumara wrote:Welcome to CodeRanch, Rob Sang!


Thank you
 
Punya Pratap Singh
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Now when I try to connect with following connection string it throws following Error.And I am using windows authentication.





 
Philip Grove
Ranch Hand
Posts: 68
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the connect string that Rob posted, that should clear up your problems. One good thing though, it is the driver that is complaining so there is no problems finding the correct driver.
 
Punya Pratap Singh
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now It is giving following Exception ,What could be the possible causes,
Please Help me.


 
Philip Grove
Ranch Hand
Posts: 68
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start a new thread to avoid getting overlooked as it is a different problem and different exception, and this time please post your code as we can't help without seeing the code.

Generally a connection refused is not a code issue, of course it can be. It is far more likely to be caused by the server no longer running in the same place or even allowing connections from the place of your code.
 
Punya Pratap Singh
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is same as above.that is why I posted it here.
 
Philip Grove
Ranch Hand
Posts: 68
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code might be the same, but the problem and the exception is another and this thread is titled "ClassNotFoundException".

Verify that you can connect to the server through other means than your code, from the same computer that your code runs on.
 
Deepthi Tanguturi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Philip Grove wrote:The code might be the same, but the problem and the exception is another and this thread is titled "ClassNotFoundException".

Verify that you can connect to the server through other means than your code, from the same computer that your code runs on.


I think,jar file was not set tot the classpath.When you can't set jar file to the classpath.This problem comes.Please check classpath by using echo command.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic