wood burning stoves 2.0*
The moose likes JDBC and the fly likes ClassNotFoundException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ClassNotFoundException" Watch "ClassNotFoundException" New topic
Author

ClassNotFoundException

Punya Pratap Singh
Ranch Hand

Joined: Nov 23, 2010
Posts: 80
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

Joined: Oct 13, 2005
Posts: 38016
    
  22
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

Joined: Aug 18, 2009
Posts: 68

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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Nov 23, 2010
Posts: 80
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

Joined: Oct 24, 2005
Posts: 58
to display classpath the command is without the assignment operator.
Punya Pratap Singh
Ranch Hand

Joined: Nov 23, 2010
Posts: 80
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

Joined: Mar 24, 2008
Posts: 3817

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?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Punya Pratap Singh
Ranch Hand

Joined: Nov 23, 2010
Posts: 80
The Code I am using is---

Ashutosh Limaye
Ranch Hand

Joined: Oct 24, 2005
Posts: 58
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
Marshal

Joined: Mar 22, 2005
Posts: 41114
    
  45
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


Ping & DNS - my free Android networking tools app
Ashutosh Limaye
Ranch Hand

Joined: Oct 24, 2005
Posts: 58
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

Joined: Nov 23, 2010
Posts: 80
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

Joined: Jul 28, 2011
Posts: 2

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

Joined: Mar 24, 2008
Posts: 3817

Welcome to CodeRanch, Rob Sang!
Rob Sang
Greenhorn

Joined: Jul 28, 2011
Posts: 2

Vijitha Kumara wrote:Welcome to CodeRanch, Rob Sang!


Thank you
Punya Pratap Singh
Ranch Hand

Joined: Nov 23, 2010
Posts: 80
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

Joined: Aug 18, 2009
Posts: 68

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

Joined: Nov 23, 2010
Posts: 80
Now It is giving following Exception ,What could be the possible causes,
Please Help me.


Philip Grove
Ranch Hand

Joined: Aug 18, 2009
Posts: 68

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

Joined: Nov 23, 2010
Posts: 80
The code is same as above.that is why I posted it here.
Philip Grove
Ranch Hand

Joined: Aug 18, 2009
Posts: 68

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

Joined: Sep 06, 2011
Posts: 17
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassNotFoundException
 
Similar Threads
JDBC Eclipse mySQL
Reg: Writing Oracle JavaStored Procedures
save/point error
PATH & CLASSPATH?
UnsupportedClassVersionError (unsupported major.minor version 50.0)