jdbc 连接 mysql 问题,偶看了好多贴还是解决不了
xfe1 2003-07-24 09:01:06 偶下载的MM.MYSQL 驱动。
JDK 安装路径是 c:\j2sdk MYSQL 路径是 C:\MYSQL
偶把驱动文件 mysql-connector-java-3.0.8-stable-bin.jar 按要求放到了C:\j2sdk\jre\lib\ext\ 下,并配置了环境变量 classpath c:\j2sdk\jre\lib\ext\mysql-connector-java-3.0.8-stable-bin.jar 不知道还少了什么?
程序文件放在 E:\xf\test\ch15\ 下
偶的代码是
import java.sql.*;
public class CreateTable
{
public static void main(String[] args)
{
Connection con=null;
try
{
Class.forName("org.git.mm.mysql.Driver").newInstance();
System.out.println("JDBC driver loaded");
con=DriverManager.getConnection("jdbc:mysql://localhost/wrox ?user=xf&password=xf");
System.out.println("Database connection established");
Statement stmt=con.createStatement();
String upd="CREATE TABLE Author(Author_ID INTEGER NOT NULL PRIMARY KEY,Author_Name char(50));";
stmt.executeUpdate(upd);
System.out.println("Table Author created");
upd="CREATE TABLE Category (Category_ID Integer NOT null PRIMARY KEY,Title_ID Integer,Author_ID Integer);";
stmt.executeUpdate(upd);
System.out.println("Table - Contribution created");
}catch(ClassNotFoundException cnfe)
{
System.out.println("ClassNotFoundException : Could not locate drive");
}
catch(SQLException cnfe)
{
System.out.println("Sqlexception" + cnfe);
}
catch(Exception e)
{
System.out.println("an unknown error occurred while connecting to the database");
}
finally
{
try
{
if(con!=null)
con.close();
}
catch(SQLException sqle)
{
System.out.println("Unable to close database connection");
}
}
}
}
提示错误为:ClassNotFoundException :cound not loacte drive
大家帮帮忙 欧在线