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();
}
}
.;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...
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
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...
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?
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>.