日期:2014-05-20  浏览次数:20785 次

初学java,关于JDBC的问题
Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
我照着网上的教程复制了mysql-connector-java-5.1.19-bin.jar到jdk的lib包中,环境变量也配置了,但还是连不到数据库 ,求路过的大侠指点……

代码如下:
package eight;
import java.sql.*;

public class Dictionary 
{
static Statement stmt;
static Connection conn;
static ResultSet rs;
public static void main(String[] args) throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/dictionary", "root", "root");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from dictionary");
while(rs.next())
{
System.out.println(rs.getInt(1)+"\t"
+rs.getString(2)+"\t"
+rs.getString(3));
}

 
if(rs!=null)
{
rs.close();
}
if(stmt!=null)
{
stmt.close();
}
if(conn!=null)
{
conn.close();
}


}

}


------解决方案--------------------
探讨
还没有呢,我就纠结了,我看网上说是要复制了jar文件再配下classpath就ok了,但我也照做了,程序也是很简单的例子程序,为什么不行呢