初学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();
}
}
}
------解决方案--------------------