MySQL的JDBC问题

genedna 2003-02-12 04:48:35
我下载了MySQL的JDBC驱动在我的机器中,在C:\JBuilder7\jdk1.3.1\jre\lib路径下。然后把这个路径加到我的机器的PATH路径中。然后写了一个测试的程序如下:
import java.sql.*;

/**
* @author Administrator
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class MySQLConnection {
public String SQLResult;

public MySQLConnection(){
// Initlization String
SQLResult = "Nothing";
//load the driver
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();

//Get the connection
Connection conn;
conn = (Connection) DriverManager.getConnection("jdbc:mysql://192.169.10.179/mysql", "root", "");

//Get database date
Statement statement = conn.createStatement();
ResultSet resultSet = (ResultSet) statement.executeQuery("Select * from user");

SQLResult = resultSet.getString(0);

//Close connection

}
catch(InstantiationException ex){
SQLResult = "InstantiationException";
}
catch(IllegalAccessException ex){
SQLResult = "IllegalAccessException";
}
catch(ClassNotFoundException ex){
SQLResult = "ClassNotFoundException";
}
catch(Exception ex){
SQLResult = "Exception";
}

}

}

另写了一个类执行它,如下:
/**
* @author Administrator
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class ConnectionExec {

/**
* Constructor for ConnectionExec.
*/
public ConnectionExec() {
super();
}

public static void main(String[] args) {
MySQLConnection mySQLConnection = new MySQLConnection();
System.out.println(mySQLConnection.SQLResult);
}
}

运行的结果总是弹出异常
ClassNotFoundException

请问各位大侠是怎么回事?
...全文
27 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lanmarco 2003-02-12
  • 打赏
  • 举报
回复
把有com.mysql.jdbc.Driver的那个包加到classpath里试试。
genedna 2003-02-12
  • 打赏
  • 举报
回复
我的PATH环境是:
C:\Program Files\Borland\Delphi7\Bin;C:\Program Files\Borland\Delphi7\Projects\Bpl\;C:\Tcl\bin;C:\Python22\.;C:\Perl\bin\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\cvsnt;C:\JBuilder7\jdk1.3.1\bin;C:\JBuilder7\jdk1.3.1\lib;C:\JBuilder7\jdk1.3.1\jre\lib

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧