还是关于路径的问题,请各位帮忙,小妹谢谢各位

rain_ok 2002-04-11 11:10:56
首先,我将环境变量改了,CLASSPATH是
.;d:\JDK1.3\lib\tools.jar;d:\tomcat\lib\common\servlet.jar;d:\jdk1.3\bin\Opta2000\Opta2000.jar;
PATH是
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;D:\jdk1.3;D:\jdk1.3\bin;D:\MSSQL7\BINN;(前面是系统的)
其次,我把ClassicDriver.java文件直接放在D:\JDK1.3\bin\ClassicDriver.java
接着,我开始编译和执行,编译D:\JDK1.3\bin>javac ClassicDriver.java
执行D:\JDK1.3\bin>java ClassicDriver,出错,显示
Exception in thread "main" java.lang.NoClassDefFoundError: ClassicDriver (wrong name:sample/ClassicDriver)
at java.lang.ClassLoader.defineClass0(NativeMethod)
at java.lang.ClassLoader.defineClass (ClassLoader.java:486)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
若是将文件放在D:\JDK1.3\bin\sample\ClassicDriver.java
执行出错信息是
Exception in thread "main" java.lang.NoClassDefFoundError: d:\jdk1.3\bin\sample\ClassicDriver
用java -classpath . ClassicDriver来运行,出错信息和D:\JDK1.3\bin>java ClassicDriver是一样的。
请各位指点迷津,小妹在此谢谢各位
...全文
48 点赞 收藏 13
写回复
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiach 2002-04-14
又没有搞错,
你的问题比我迟发两分钟,却有这么多人捧场,我的问题和你挨着却没人回复,难道IT这么缺妹妹呀!!!
回复
Times2001 2002-04-14
去掉package sample;不会不可以吧?
你去掉后重新javac java
我试过,可以的
不然就不去掉那句,直接把.class放到sample里面
然后用java sample.ClassicDriver
就可以了

回复
CHARGING 2002-04-13
把文件放到d:\tomcat\webapps\examples\WEB-INF\classes\Sample\目录下试试看.
回复
qlqllu 2002-04-13
如果没有ctrl-c ctrl-v 大家还会不会把大段的代码写在这/?
回复
rain_ok 2002-04-12
去掉package sample;的方法我试了,不可以,请问是应该用啥语句执行?谢谢
回复
Times2001 2002-04-12
或者在程序中去掉package sample;
回复
Times2001 2002-04-12
把class放到sample里面
然后用java sample.ClassicDriver
就可以了
回复
rain_ok 2002-04-11
/*
i-net software provides programming examples for illustration only, without warranty
either expressed or implied, including, but not limited to, the implied warranties
of merchantability and/or fitness for a particular purpose. This programming example
assumes that you are familiar with the programming language being demonstrated and
the tools used to create and debug procedures. i-net software support professionals
can help explain the functionality of a particular procedure, but they will not modify
these examples to provide added functionality or construct procedures to meet your
specific needs.
?i-net software 2000

An example to demonstrate how to connect and use the driver with the JDBC 1.22 interface.
(This driver requires the JDBC 2.0 interface and a JDK 1.2 or higher)

*/

package sample;

import java.sql.*; // JDBC package

public class ClassicDriver
{

public static void main(String args[] ){
String url = "jdbc:inetdae7:localhost:1433"; // use your hostname and port number here
String login = "sa"; // use your login here
String password = ""; // use your password here

try {
DriverManager.setLogStream(System.out); // to create more info
// for technical support

Class.forName("com.inet.tds.TdsDriver").newInstance();
//or
//new com.inet.tds.TdsDriver();


//set a timeout for login and query
DriverManager.setLoginTimeout(10);


//open a connection to the database
Connection connection = DriverManager.getConnection(url,login,password);

//to get the driver version
DatabaseMetaData conMD = connection.getMetaData();
System.out.println("Driver Name:\t" + conMD.getDriverName());
System.out.println("Driver Version:\t" + conMD.getDriverVersion());

//select a database
connection.setCatalog( "master" );

//create a statement
Statement st = connection.createStatement();

//execute a query
ResultSet rs = st.executeQuery("SELECT * FROM sysusers");

// read the data and put it to the console
while (rs.next()){
for(int j=1; j<=rs.getMetaData().getColumnCount(); j++){
System.out.print( rs.getObject(j)+"\t");
}
System.out.println();
}


//close the objects
st.close();
connection.close();

} catch(Exception e) {
e.printStackTrace();
}
}
}
这是一个JDBC DRIVER (OPTA2000)下面的SAMPLE中测试数据库连接的JAVA文件。谢谢各位
回复
可乐加水 2002-04-11
对,没有代码很难说清楚的
回复
zhjx_10 2002-04-11
代码贴出来
回复
zhjx_10 2002-04-11
将编译好的class放在sample目录下面看看
回复
dylanwolf 2002-04-11
把 package sample 去掉试试。
回复
rain_ok 2002-04-11
代码帖了。为何没有人帮忙啊。我赶设计的,麻烦大家了。小妹在此谢谢大家
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告