re: "java.lang.NoClassDefFoundError"错误——一个关于classpath设置的问题
2006-11-19 16:10 |
这是我拷的一个例子,在编译的时候可以通过,但在执行的时候去总出现先您那样的错误。不知如何解决。我是一个初学者还请您多多指点。
package stuman;
import java.io.*;
import java.sql.*;
public class sqlBean{///
public Connection conn=null;
public ResultSet rs=null;
private String DatabaseDriver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
private String DatabaseConnStr="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=educationi,'edu','edu'";
private String strcon = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=educationi";
private String strusr = "edu";
private String stupwd = "edu";
public void setDatabaseDriver(String Driver){
this.DatabaseDriver=Driver;
}
public String getDatabaseDriver(){
return (this.DatabaseDriver);
}
public void setDatabaseConnStr(String ConnStr){
this.DatabaseConnStr=ConnStr;
}
public String getDatabaseConnStr(){
return (this.DatabaseConnStr);
}
public sqlBean(){/////构造函数
try{
Class.forName(DatabaseDriver);
}
catch(java.lang.ClassNotFoundException e){
System.err.println("加载驱动器有错误:"+e.getMessage( ));
System.out.print("执行插入有错误:"+e.getMessage());//输出到客户端
}
}
public int executeInsert(String sql){
int num=0;
try{
conn = DriverManager.getConnection(strcon,strusr,stupwd);
Statement stmt=conn.createStatement( );
num=stmt.executeUpdate(sql);
}
catch(SQLException ex){
System.err.println("执行插入有错误:"+ex.getMessage() );
System.out.print("执行插入有错误:"+ex.getMessage());//输出到客户端
}
CloseDataBase();
return num;
}
// display data
public ResultSet executeQuery(String sql){
rs=null;
try{
conn = DriverManager.getConnection(strcon,strusr,stupwd);
Statement stmt=conn.createStatement( );
rs=stmt.executeQuery(sql);
}
catch(SQLException ex){
System.err.println("执行查询有错误:"+ex.getMessage() );
System.out.print("执行查询有错误:"+ex.getMessage()); //输出到客户端
}
return rs;
}
// delete data
public int executeDelete(String sql){
int num=0;
try{
conn = DriverManager.getConnection(strcon,strusr,stupwd);
Statement stmt=conn.createStatement( );
num=stmt.executeUpdate(sql);
}
catch(SQLException ex){
System.err.println("执行删除有错误:"+ex.getMessage() );
System.out.print("执行删除有错误:"+ex.getMessage()); //输出到客户端
}
CloseDataBase();
return num;
}
//////////////////
public void CloseDataBase(){
try{
conn.close();
}
catch(Exception end){
System.err.println("执行关闭Connection对象有错误:"+end.getMessage( ) );
System.out.print("执行执行关闭Connection对象有错误:有错误:"+end.getMessage()); //输出到客户端
}
}
}
回复 更多评论