Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 继续问 (java.lang.ClassNotFoundException)
newchi



发贴: 0
积分: 0
于 2004-01-05 08:42 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
C:\aa>javac Hello.java
Hello.java:6: unreported exception java.lang.ClassNotFoundException; must be cau
ght or declared to be thrown
Class.forName("org.gjt.mm.mysql.Driver");
^
1 error
编译的时候出这个错误。
但是当我抛出异常的时候错误依然
代码
import java.sql.*;

public class Hello {
public static void main(String[] args){
try{
Class.forName("org.gjt.mm.mysql.Driver");
Connection

conn=DriverManager.getConnection("jdbc:mysql://localhost/test","root","

");
Statement stmt=conn.createStatement();

stmt.close();
conn.close();
}catch(SQLException Sqle){
System.out.println(Sqle);
}
}
}


why edited on 2004-01-05 11:20

作者 Re:继续问 [Re:newchi]
beck



发贴: 0
积分: 0
于 2004-01-05 09:44 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
把mysql驱动加到classpath中。


作者 mysql的JDBC驱动在classpath里如何配置 [Re:newchi]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2004-01-05 11:32 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
请在原话题继续提问,不要开新话题哦,谢谢啦!

newchi Posted on 2004-01-04 22:28

我装的是j2sdk1.4.2是这样的。
C:\j2sdk1.4.2
那么mysql的JDBC驱动该放在什么地方。如何配置。
还有。就是我这样运行
C:\java aa.fram
aa是fram.class 所在的目录。为什么不行?
提示错误为:
C:\>java aa.Fram
Exception in thread "main" java.lang.NoClassDefFoundError: aa/Fram (wron name: Fram)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
是不是我的环境变量配置有错误?????


why edited on 2004-01-05 20:48

作者 Re:继续问 (java.lang.ClassNotFoundException) [Re:newchi]
Janas



发贴: 0
积分: 0
于 2004-01-05 17:45 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你只用
catch(SQLException Sqle)
当然不行
加上
catch(Exception ex)
应该就可以来



作者 Re:继续问 (java.lang.ClassNotFoundException) [Re:newchi]
hitaco





发贴: 432
积分: 31
于 2004-01-05 20:22 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
You should catch all the checked exception unless you rethrow them out.

Regarding mysql driver, the followings are some of my opinions:
1) Download J/Connector from MySQL homepage.
2) You need not include mysql library in classpath when you compile the application, because your application will use Class.forName() to register the driver, hence it's entirely runtime dependency, not compile time
3)
Put mysql driver anywhere you like, for example "C:\Mysql\Driver" directory.

java -classpath %CLASSPATH%;C:\Mysql\Driver\mysql-connector-java-3.0.9-stable-bin.jar aa.Fram

make sure you are in the corrent directory when you invoke java command.

Good luck!




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923