Home > Archive > SQL Server JDBC > February 2006 > Class Not Found Exception









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Class Not Found Exception
David

2006-02-03, 8:23 pm

Not new to programming, but very new to Java...

I have written a Java app that is attempting to connect to a local SQL
Server. I've downloaded and installed Microsoft's JDBC driver (it appeared to
install okay).

The following code is throwing the Class Not Found exception at the class
statement. Is there something more that I need to do with the driver that
I've installed or am I missing something in the code?

thanks for any help.


java.sql.Connection connection = null;
String username = "myName";
String password = "myPass";
String URL = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String conn = " jdbc:microsoft:sqlse
rver:// localhost:1433:Datab
aseName=myDB";

try {
Class.forName(URL).newInstance();
connection = DriverManager.getConnection(conn, username, password);

... rest of code


Evan T. Basalik

2006-02-07, 11:23 am

If you are using the SQL Server 2000 version of the driver, you will need:

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

and

CLASSPATH=. ;C:\JDBC\DDSP3\lib\m
sbase. jar;C:\JDBC\DDSP3\li
b\mssqlserver. jar;C:\JDBC\DDSP3\li
b\msutil.jar


If you are using the SQL Server 2005 version, you will need:

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

and

CLASSPATH=.;C:\JDBC\sqljdbc_1.0\enu\sqljdbc.jar

--------------------
>Thread-Topic: Class Not Found Exception
>thread-index: AcYo+3NRe1QkARdfQGCC
aXbKbFyiqg==
>X-WBNR-Posting-Host: 147.56.101.155
>From: "=?Utf-8?B?RGF2aWQ=?=" <David@discussions.microsoft.com>
>Subject: Class Not Found Exception
>
>Not new to programming, but very new to Java...
>
>I have written a Java app that is attempting to connect to a local SQL
>Server. I've downloaded and installed Microsoft's JDBC driver (it appeared to
>install okay).
>
>The following code is throwing the Class Not Found exception at the class
>statement. Is there something more that I need to do with the driver that
>I've installed or am I missing something in the code?
>
>thanks for any help.
>
>
>java.sql.Connection connection = null;
>String username = "myName";
>String password = "myPass";
>String URL = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
>String conn = " jdbc:microsoft:sqlse
rver:// localhost:1433:Datab
aseName=myDB";
>
>try {
> Class.forName(URL).newInstance();
> connection = DriverManager.getConnection(conn, username, password);
>
> ... rest of code
>
>
>



--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.

David

2006-02-08, 1:23 pm

Thanks for replying...
Okay... I've tweaked the classpath (I'm working in Eclipse), and am now
getting past the class.forname statement. However, I am getting a
SQLException error at the DriverManager.getconnection statement. "The error
is Unable to connect. Invalid URL". Would I be getting this because of the
URL defined in the new instance of the class, or because of the path defined
in the sqlserver connection variable? I've tried tweaking both, but both seem
to be valid.

thanks again for your help.



"Evan T. Basalik (MSFT)" wrote:

> If you are using the SQL Server 2000 version of the driver, you will need:
>
> Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
>
> and
>
> CLASSPATH=. ;C:\JDBC\DDSP3\lib\m
sbase. jar;C:\JDBC\DDSP3\li
b\mssqlserver. jar;C:\JDBC\DDSP3\li
b\msutil.jar
>
>
> If you are using the SQL Server 2005 version, you will need:
>
> Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
>
> and
>
> CLASSPATH=.;C:\JDBC\sqljdbc_1.0\enu\sqljdbc.jar
>
> --------------------
>
>
> --
>
> This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
> http://www.microsoft.com/info/cpyright.htm
>
> Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.
>
>

David

2006-02-08, 8:23 pm

Nevermind...
Colons... semicolons...
I was swept up in a new development environment that I missed a syntax error
(I had placed a colon between the server port and the database name instead
of a semicolon...)


"David" wrote:
[color=darkred]
> Thanks for replying...
> Okay... I've tweaked the classpath (I'm working in Eclipse), and am now
> getting past the class.forname statement. However, I am getting a
> SQLException error at the DriverManager.getconnection statement. "The error
> is Unable to connect. Invalid URL". Would I be getting this because of the
> URL defined in the new instance of the class, or because of the path defined
> in the sqlserver connection variable? I've tried tweaking both, but both seem
> to be valid.
>
> thanks again for your help.
>
>
>
> "Evan T. Basalik (MSFT)" wrote:
>
ÁõÑÐ LiuYan

2006-02-20, 11:23 am

Very useful, it takes me 1 night time to resole this issue.
I hope microsoft can HIGHLIGHT this difference in the document of
SQLServer2005 JDBC.

# SQL Server 2000 version of the driver
#config.jdbc.driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
# SQL Server 2005 version
config.jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver



"Evan T. Basalik (MSFT)" <evanba@online.microsoft.com> дÈëÏûÏ¢ÐÂÎÅ:sxLVxjA
LGHA.3764@TK2MSFTNGXA02.phx.gbl...
> If you are using the SQL Server 2000 version of the driver, you will need:
>
> Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
>
> and
>
> CLASSPATH=. ;C:\JDBC\DDSP3\lib\m
sbase. jar;C:\JDBC\DDSP3\li
b\mssqlserver. jar;C:\JDBC\DDSP3\li
b\msutil.jar
>
>
> If you are using the SQL Server 2005 version, you will need:
>
> Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
>
> and
>
> CLASSPATH=.;C:\JDBC\sqljdbc_1.0\enu\sqljdbc.jar
>
> --------------------
>
>
> --
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights. Use of included script samples are subject to the terms specified
> at
> http://www.microsoft.com/info/cpyright.htm
>
> Note: For the benefit of the community-at-large, all responses to this
> message are best directed to the newsgroup/thread from which they
> originated.
>



LiuYan 刘研

2006-02-20, 11:23 am

And also the difference of "database connection URL"

# SQL Server 2000 version
#config.jdbc.driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
#config.jdbc. url=jdbc:microsoft:s
qlserver:// localhost:1433;Datab
aseName=HLGG

# SQL Server 2005 version
config.jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
config.jdbc.url=jdbc:sqlserver:// localhost:1433;Datab
aseName=HLGG


-----------------------------
LiuYan 刘ç_”
Email: liu.yan@china-motion.com
Tel: 0086-755-82189432



"刘ç_” LiuYan" wrote:

> Very useful, it takes me 1 night time to resole this issue.
> I hope microsoft can HIGHLIGHT this difference in the document of
> SQLServer2005 JDBC.
>
> # SQL Server 2000 version of the driver
> #config.jdbc.driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
> # SQL Server 2005 version
> config.jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver


Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2009 droptable.com