求救啊,我菜鸟,望大侠们多帮助啊
代码应该没有错数据库也都是对的,还有eclipse是自动跳入debug界面的。Myeclipse是9.0的,jdk,jre是1.6的。在线等高手们啊。
这是Myeclipse的debug结果:ruitest.JDBCsxt at localhost:50215
Thread [main] (Suspended (exception
ClassNotFoundException))
URLClassLoader$1.run() line: 200
AccessController.doPrivileged(PrivilegedExceptionAction<T>, AccessControlContext) line: not available [native method]
Launcher$AppClassLoader(URLClassLoader).findClass(String) line: 188
Launcher$AppClassLoader(ClassLoader).loadClass(String, boolean) line: 307
Launcher$AppClassLoader.loadClass(String, boolean) line: 301
Launcher$AppClassLoader(ClassLoader).loadClass(String) line: 252
Launcher$AppClassLoader(ClassLoader).loadClassInternal(String) line: 320
E:\SoftwarePrograms\Myeclipse9\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\bin\javaw.exe (2012-6-18 上午09:37:24)
这里是命令行运行结果:Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。
C:\Users\Administrator>cd C:\Users\Administrator\Desktop\servey
C:\Users\Administrator\Desktop\servey>java TestMysqlConnection
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at TestMysqlConnection.main(TestMysqlConnection.java:13)
C:\Users\Administrator\Desktop\servey>
下面是程序源代码:
JScript code
package ruitest;
import java.sql.*;
public class TestMysqlConnection {
/**
* @param args
*/
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager
.getConnection("jdbc:mysql://localhost/mydata?user=root&password=mysql");
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from dept");
while (rs.next()) {
System.out.println(rs.getString("deptno"));
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
} finally {
try {
if(rs != null) {
rs.close();
rs = null;
}
if(stmt != null) {
stmt.close();
stmt = null;
}
if(conn != null) {
conn.close();
conn = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
------解决方案--------------------
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
没有找到mysql 这个jar文件,你放哪里去了~~
------解决方案--------------------你之前尝试其他jdbc成功了么?我很怀疑是配置不正确,大概意思就是说你得有mysql而且你的java知道它在哪里