问题描述
我做的是一个java应用程序。数据库连接语句是是放在一个java类文件里的,主要代码如下:publicclassDbUtil{privateStringdbUrl="jdbc:mysql://localhost:3306/library";privateStringdbUser="root";privateStringdbPassword="root";//获取数据库连接publicConnectiongetCon()throwsException{Class.forName("com.mysql.jdbc.Driver").newInstance();Connectioncon=DriverManager.getConnection(dbUrl,dbUser,dbPassword);System.out.println(con);returncon;}//关闭数据集publicvoidcloseCon(Connectioncon)throwsException{if(con!=null){con.close();}}//关闭数据集publicvoidcloseRs(ResultSetrs)throwsException{if(rs!=null){rs.close();}}用一个JFrame文件调用上述java类里的连接数据库的方法,主要代码如下:publicclassLogOnFrmextendsjavax.swing.JFrame{DbUtilutil=newDbUtil();LogOnUtillogOnUtil=newLogOnUtil();publicstaticConnectioncon;/**CreatesnewformLogOnFrm*/publicLogOnFrm(){initComponents();this.setLocationRelativeTo(null);//设置居中显示frametry{con=util.getCon();}catch(Exceptionex){ex.printStackTrace();}}}运行程序会出现错误信息如下:java.lang.ClassNotFoundException:com.mysql.jdbc.Driveratjava.net.URLClassLoader$1.run(URLClassLoader.java:220)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.net.URLClassLoader.findClass(URLClassLoader.java:208)atjava.lang.ClassLoader.loadClass(ClassLoader.java:323)atsun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)atjava.lang.ClassLoader.loadClass(ClassLoader.java:268)atjava.lang.ClassLoader.loadClassInternal(ClassLoader.java:336)atjava.lang.Class.forName0(NativeMethod)atjava.lang.Class.forName(Class.java:186)atcom.wind.util.DbUtil.getCon(DbUtil.java:26)atcom.wind.view.LogOnFrm.<init>(LogOnFrm.java:51)atcom.wind.view.LogOnFrm$3.run(LogOnFrm.java:202)atjava.awt.event.InvocationEvent.dispatch(InvocationEvent.java:226)atjava.awt.EventQueue.dispatchEvent(EventQueue.java:602)atjava.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)atjava.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)atjava.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)atjava.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)atjava.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)atjava.awt.EventDispatchThread.run(EventDispatchThread.java:138)成功生成(总时间:5秒)同时,服务器控制台日志里面没有内容(已经启动了)。注:mysql的驱动程序已经放到指定的文件夹中了。而且用其他的程序测试过,可以显示出表的内容。想请教一下,哪位大侠知道这是哪里的问题呀!~~~~~跪求~~~~~~~~~~~~~~~~~