Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What's going wrong?

1 view
Skip to first unread message

oglixari

unread,
Apr 28, 2002, 4:18:06 AM4/28/02
to
It is a big supprise to me, when I awared of the Microsoft released the
JDBC for MS SQL Server 2000.
I have download Microsoft's JDBC driver is for SQL Server 2000 and
installed it.
while I use a piece of code, also download from website see the following
text, to test the connection ability...
(Java2 SE 1.4.0 + MS SQL Server 2000 + JDBC for MSSQL version2.2.0002 )

There are no errors or wranning appeared during compiling. "javac test.java"

Then I try to execute it by using "java test".... lots of error appeared
like following list:

--------------------------------------------------------------

c:\java\project>java test
java.lang.ClassNotFoundException:
com.microsoft.jdbc.sqlserver.SQLServerDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:262)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:130)
at test.getConnection(test.java:16)
at test.displayDbProperties(test.java:30)

------------------------------------------------------------

I also try to us jdb ,java debug tool in java_location\bin\, what a
supprise! it works ...look this...

-------------------------------------------------------------

c:\java\project>jdb
Initializing jdb ...
> run test
run test
>
VM Started: Con complete
Driver Name: SQLServer
Driver Version: 2.2.0002
Database Name: Microsoft SQL Server
Database Version: Microsoft SQL Server 2000 - 8.00.194 (Intel X86)
Aug 6 2000 00:57:48
Copyright (c) 1988-2000 Microsoft Corporation
Developer Edition on Windows NT 5.0 (Build 2195: Service Pack 2)

Schema: dbo
Schema: guest
catalog: master
catalog: msdb
catalog: Northwind
catalog: pubs
catalog: tempdb
Catalog Seperator :.
Table: pubs.dbo.authors
Table: pubs.dbo.discounts
Table: pubs.dbo.employee
Table: pubs.dbo.jobs
Table: pubs.dbo.pub_info
Table: pubs.dbo.publishers
Table: pubs.dbo.roysched
Table: pubs.dbo.sales
Table: pubs.dbo.stores
Table: pubs.dbo.titleauthor
Table: pubs.dbo.titles

The application exited

----------------------------------------------------------------------------
----------------

I dont't know what's wrong with the it (environment, path or driver itself),
and confused me so much.
the following codes is about test.java

----------------------------------------------------------------------------
-----------------

/*
This code is to test SQLServer Connectivity
*/
import java.sql.*;

public class test{

private java.sql.Connection con = null;


public test(){}

private Connection getConnection() throws Exception{
con=null;
try{

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con =
DriverManager.getConnection("jdbc:microsoft:sqlserver://metro:1433;DatabaseN
ame=pubs","sa","");
if(con!=null) System.out.println("Con complete");
} catch(SQLException e){
e.printStackTrace();
System.out.println("Error Trace in
getConnection() : " + e.getMessage());
}
return con;
}

public void displayDbProperties(){
DatabaseMetaData dm = null;
ResultSet rs = null;
try{
con= this.getConnection();
if(con!=null){
dm = con.getMetaData();
System.out.println("Driver Name: "+
dm.getDriverName());
System.out.println("Driver Version: "+
dm.getDriverVersion ());
System.out.println("Database Name: "+
dm.getDatabaseProductName());
System.out.println("Database Version: "+
dm.getDatabaseProductVersion());
rs = dm.getSchemas();
while(rs!=null&&rs.next()){
System.out.println("Schema: "+
rs.getString(1));
}
rs.close();
rs = null;
rs = dm.getCatalogs();
while(rs!=null&&rs.next()){
System.out.println("catalog: "+
rs.getString(1));
}
rs.close();
rs = null;
System.out.println("Catalog Seperator :"+
dm.getCatalogSeparator());
String[] tbl_types={"TABLE"};
rs =
dm.getTables("pubs","%","%",tbl_types);
while(rs!=null&&rs.next()){
System.out.println("Table: "+
rs.getString(1)+ "." + rs.getString(2)+"."+ rs.getString(3));
}

}else System.out.println("Error: No active
Connection");
}catch(Exception e){
e.printStackTrace();
}
dm=null;
}

private void closeConection(Connection con){
try{
if(con!=null)
con.close();
con=null;
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception
{
test myDbTest = new test();
myDbTest.displayDbProperties();
}
}

oglixari

unread,
Apr 28, 2002, 9:43:11 AM4/28/02
to

David Bezjak

unread,
Apr 29, 2002, 4:41:10 AM4/29/02
to
I had som problems with this but it was my CLASSPATH that was messed up. Do
you have something like this in your classpath:

.;c:\utv\database\msutil.jar;c:\utv\database\msbase.jar;c:\utv\database\mssq
lserver.jar

Note that the "." has to be first.

"oglixari" <ogli...@hotmail.com> wrote in message
news:uVWTBrr7BHA.1368@tkmsftngp03...

Jon Skeet

unread,
Apr 30, 2002, 3:50:12 AM4/30/02
to
David Bezjak <da...@wingenius.com> wrote:
> I had som problems with this but it was my CLASSPATH that was messed up. Do
> you have something like this in your classpath:
>
> .;c:\utv\database\msutil.jar;c:\utv\database\msbase.jar;c:\utv\database\mssq
> lserver.jar

It's easier (IMO) to not use a classpath environment variable at all,
and use the extension mechanism. See
http://www.pobox.com/~skeet/java/extensions.html
and
http://www.pobox.com/~skeet/java/classpath.html

> Note that the "." has to be first.

It shouldn't have to be.

--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

David Bezjak

unread,
Apr 30, 2002, 9:34:18 AM4/30/02
to
Well I'm not a java expert (by far) but I learned the hard way:

http://forum.java.sun.com/thread.jsp?forum=54&thread=246576

Maybe you know why it mattered that time?

"Jon Skeet" <sk...@pobox.com> wrote in message
news:MPG.17385d11d...@msnews.microsoft.com...

Jon Skeet

unread,
May 1, 2002, 1:39:35 PM5/1/02
to
David Bezjak <da...@wingenius.com> wrote:
> Well I'm not a java expert (by far) but I learned the hard way:
>
> http://forum.java.sun.com/thread.jsp?forum=54&thread=246576
>
> Maybe you know why it mattered that time?

It shouldn't do - I suspect something very strange was happening. Do you
have an example program which I could try to recreate the problem with?

Sridhar Paladugu[MS]

unread,
May 7, 2002, 1:56:59 PM5/7/02
to
Hi,

Did you updated your class path?

Thanks

Sridhar Paladugu
Microsoft Developer Support
JDBC Webdata


This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Strategic Technology Protection
Program and to order
your FREE Security Tool Kit, please visit
<http://www.microsoft.com/security>.


0 new messages