当前位置: 技术问答>java相关
请大家帮忙看看下面问题出在哪里
来源: 互联网 发布时间:2015-07-30
本文导语: 请大家帮忙看看下面问题出在哪里 错误提示是: java.lang.NoClassDefFoundError: RecruitTypeDict RecruitTypeDict.java //package XKSoft.System; import java.io.*; import java.sql.*; import java.lang.*; import java.util.*; import java.util.Date; //import XKSoft...
请大家帮忙看看下面问题出在哪里
错误提示是:
java.lang.NoClassDefFoundError: RecruitTypeDict
RecruitTypeDict.java
//package XKSoft.System;
import java.io.*;
import java.sql.*;
import java.lang.*;
import java.util.*;
import java.util.Date;
//import XKSoft.DBConnection.DBConnectionBean;
import DBConnectionBean;
public class RecruitTypeDict
{
private Connection myConn;
private String RecruitTypeName; //招生类型名称
private String Numbers; //统一编号
DBConnectionBean myObj = new DBConnectionBean();
public void RecruitTypeDictBean()
{
myObj = DBConnectionBean.getInstance();
myConn = myObj.getConnection();
}
//获得招生类型名称
public String getRecruitTypeName()
{
return RecruitTypeName;
}
//赋值给招生类型名称
public void setRecruitTypeName(String RecruitTypeName)
{
this.RecruitTypeName = RecruitTypeName;
}
//获得统一编号
public String getNumbers()
{
return Numbers;
}
//赋值给统一编号
public void setNumbers(String Numbers)
{
this.Numbers = Numbers;
}
//增加招生类型函数
public boolean addRecruitType()
{
boolean InsertSucceed = false;
String sql = "insert into X_Pub_RecruitType(RecruitTypeName, Number) values (" + RecruitTypeName + ", " + Numbers + ")";
try
{
Statement stmt = myConn.createStatement();
InsertSucceed = stmt.execute(sql);
}
catch(SQLException e)
{
System.out.println("错误:" + e.toString());
}
return InsertSucceed;
}
//增加招生类型函数
public boolean updateRecruitType(int RecruitTypeID)
{
boolean UpdateSucceed = false;
String sql = "update X_Pub_RecruitType set RecruitTypeName="+RecruitTypeName+", Number="+Numbers+" where RecruitType="+RecruitTypeID;
try
{
Statement stmt = myConn.createStatement();
UpdateSucceed = stmt.execute(sql);
}
catch(SQLException e)
{
System.out.println("错误:" + e.toString());
}
return UpdateSucceed;
}
//删除招生类型
public boolean deleteRecruitType(String RecruitType)
{
boolean DeleteSucceed = false;
String sql="delete from X_Pub_RecruitType where RecruitType="+RecruitType;
try
{
Statement stmt = myConn.createStatement();
DeleteSucceed = stmt.execute(sql);
}
catch (SQLException e)
{
System.out.println("错误"+e.toString());
}
return DeleteSucceed;
}
//显示所有的招生类型记录
public ResultSet SelectRecruitType()
{
ResultSet rs = null;
String Sql;
Sql="select * from x_pub_RecruitType";
try
{
Statement stmt = myConn.createStatement();
rs = stmt.executeQuery(Sql);
}
catch(SQLException e)
{
System.out.println("错误:" + e.toString());
}
return rs;
}
//根据招生ID查询招生类型记录
public ResultSet SelectRecruitTypeID(int RecruitTypeID)
{
ResultSet rs = null;
String Sql;
Sql="select * from X_Pub_RecruitType where RecruitType="+RecruitTypeID;
try
{
Statement stmt = myConn.createStatement();
rs = stmt.executeQuery(Sql);
}
catch(SQLException e)
{
System.out.println("错误:" + e.toString());
}
return rs;
}
public static void main(String[] args)
{
RecruitTypeDict objRecruits= new RecruitTypeDict();
objRecruits.RecruitTypeDictBean();
ResultSet rs=objRecruits.SelectRecruitType();
try
{
while(rs.next())
{
System.out.println(rs.getInt("RecruitType"));
}
}
catch(SQLException e)
{
System.out.println("error:"+e.getMessage());
e.printStackTrace();
}
}
}
===========================================
DBConnectionBean.java
//package XKSoft.DBConnection;
import java.io.*;
import java.sql.*;
import java.util.*;
public class DBConnectionBean
{
public DBConnectionBean()
{
conn = null;
}
public static synchronized DBConnectionBean getInstance()
{
if(instance == null)
instance = new DBConnectionBean();
return instance;
}
public Connection getConnection()
{
if(conn == null)
conn = newConnection();
return conn;
}
private synchronized Connection newConnection()
{
java.io.InputStream inputstream = getClass().getResourceAsStream("db.properties");
Properties properties = new Properties();
try
{
properties.load(inputstream);
}
catch(Exception exception)
{
System.err.println("u4E0Du80FDu8BFBu53D6u5C5Eu6027u6587u4EF6.u8BF7u786Eu4FDDdb.propertiesu5728CLASSPATHu6307u5B9Au7684u8DEFu5F84u4E2D");
return null;
}
String s = properties.getProperty("logfile", "DBConnectionManager.log");
try
{
log = new PrintWriter(new FileWriter(s, true), true);
}
catch(IOException ioexception)
{
System.err.println("u65E0u6CD5u6253u5F00u65E5u5FD7u6587u4EF6: " + s);
log = new PrintWriter(System.err);
}
conn = createConnection(properties);
return conn;
}
private Connection createConnection(Properties properties)
{
for(Enumeration enumeration = properties.propertyNames(); enumeration.hasMoreElements();)
{
String s = (String)enumeration.nextElement();
if(s.endsWith(".url"))
{
String s1 = s.substring(0, s.lastIndexOf("."));
String s2 = properties.getProperty(s1 + ".url");
if(s2 == null)
{
log("u6CA1u6709u4E3Au8FDEu63A5u6C60" + s1 + "u6307u5B9AURL");
} else
{
String s3 = properties.getProperty("drivers");
String s4 = properties.getProperty(s1 + ".user");
String s5 = properties.getProperty(s1 + ".password");
String s6 = properties.getProperty(s1 + ".maxconn", "0");
int i;
try
{
i = Integer.valueOf(s6).intValue();
}
catch(NumberFormatException numberformatexception)
{
log("u9519u8BEFu7684u6700u5927u8FDEu63A5u6570u9650u5236: " + s6 + " .u8FDEu63A5u6C60: " + s1);
boolean flag = false;
}
log("u6210u529Fu521Bu5EFAu8FDEu63A5u6C60" + s1);
try
{
Class.forName(s3).newInstance();
Connection connection = DriverManager.getConnection(s2, s4, s5);
//log(new Date() + ":t" + "u6210u529Fu5EFAu7ACBu8FDEu7ED3");
return connection;
}
catch(Exception exception)
{
//log(new Date() + ":t" + "u65E0u6CD5u5EFAu7ACBu8FDEu7ED3(" + exception.toString() + ")");
}
}
}
}
return null;
}
private void log(String s)
{
//log.println(new Date() + ":t" + s);
}
public synchronized void release()
{
try
{
conn.close();
log("u5173u95EDu6240u6709u8FDEu7ED3uFF01");
log.close();
}
catch(SQLException sqlexception)
{
log("u65E0u6CD5u5173u95EDu8FDEu63A5u6C60u4E2Du7684u8FDEu63A5: (" + sqlexception.toString() + ")");
}
}
private static DBConnectionBean instance;
private PrintWriter log;
private Connection conn;
}
=============================
db.properties
drivers=com.microsoft.jdbc.sqlserver.SQLServerDriver
logfile=C:\WINNT\System32\log.txt
access.url=jdbc:microsoft:sqlserver:/
错误提示是:
java.lang.NoClassDefFoundError: RecruitTypeDict
RecruitTypeDict.java
//package XKSoft.System;
import java.io.*;
import java.sql.*;
import java.lang.*;
import java.util.*;
import java.util.Date;
//import XKSoft.DBConnection.DBConnectionBean;
import DBConnectionBean;
public class RecruitTypeDict
{
private Connection myConn;
private String RecruitTypeName; //招生类型名称
private String Numbers; //统一编号
DBConnectionBean myObj = new DBConnectionBean();
public void RecruitTypeDictBean()
{
myObj = DBConnectionBean.getInstance();
myConn = myObj.getConnection();
}
//获得招生类型名称
public String getRecruitTypeName()
{
return RecruitTypeName;
}
//赋值给招生类型名称
public void setRecruitTypeName(String RecruitTypeName)
{
this.RecruitTypeName = RecruitTypeName;
}
//获得统一编号
public String getNumbers()
{
return Numbers;
}
//赋值给统一编号
public void setNumbers(String Numbers)
{
this.Numbers = Numbers;
}
//增加招生类型函数
public boolean addRecruitType()
{
boolean InsertSucceed = false;
String sql = "insert into X_Pub_RecruitType(RecruitTypeName, Number) values (" + RecruitTypeName + ", " + Numbers + ")";
try
{
Statement stmt = myConn.createStatement();
InsertSucceed = stmt.execute(sql);
}
catch(SQLException e)
{
System.out.println("错误:" + e.toString());
}
return InsertSucceed;
}
//增加招生类型函数
public boolean updateRecruitType(int RecruitTypeID)
{
boolean UpdateSucceed = false;
String sql = "update X_Pub_RecruitType set RecruitTypeName="+RecruitTypeName+", Number="+Numbers+" where RecruitType="+RecruitTypeID;
try
{
Statement stmt = myConn.createStatement();
UpdateSucceed = stmt.execute(sql);
}
catch(SQLException e)
{
System.out.println("错误:" + e.toString());
}
return UpdateSucceed;
}
//删除招生类型
public boolean deleteRecruitType(String RecruitType)
{
boolean DeleteSucceed = false;
String sql="delete from X_Pub_RecruitType where RecruitType="+RecruitType;
try
{
Statement stmt = myConn.createStatement();
DeleteSucceed = stmt.execute(sql);
}
catch (SQLException e)
{
System.out.println("错误"+e.toString());
}
return DeleteSucceed;
}
//显示所有的招生类型记录
public ResultSet SelectRecruitType()
{
ResultSet rs = null;
String Sql;
Sql="select * from x_pub_RecruitType";
try
{
Statement stmt = myConn.createStatement();
rs = stmt.executeQuery(Sql);
}
catch(SQLException e)
{
System.out.println("错误:" + e.toString());
}
return rs;
}
//根据招生ID查询招生类型记录
public ResultSet SelectRecruitTypeID(int RecruitTypeID)
{
ResultSet rs = null;
String Sql;
Sql="select * from X_Pub_RecruitType where RecruitType="+RecruitTypeID;
try
{
Statement stmt = myConn.createStatement();
rs = stmt.executeQuery(Sql);
}
catch(SQLException e)
{
System.out.println("错误:" + e.toString());
}
return rs;
}
public static void main(String[] args)
{
RecruitTypeDict objRecruits= new RecruitTypeDict();
objRecruits.RecruitTypeDictBean();
ResultSet rs=objRecruits.SelectRecruitType();
try
{
while(rs.next())
{
System.out.println(rs.getInt("RecruitType"));
}
}
catch(SQLException e)
{
System.out.println("error:"+e.getMessage());
e.printStackTrace();
}
}
}
===========================================
DBConnectionBean.java
//package XKSoft.DBConnection;
import java.io.*;
import java.sql.*;
import java.util.*;
public class DBConnectionBean
{
public DBConnectionBean()
{
conn = null;
}
public static synchronized DBConnectionBean getInstance()
{
if(instance == null)
instance = new DBConnectionBean();
return instance;
}
public Connection getConnection()
{
if(conn == null)
conn = newConnection();
return conn;
}
private synchronized Connection newConnection()
{
java.io.InputStream inputstream = getClass().getResourceAsStream("db.properties");
Properties properties = new Properties();
try
{
properties.load(inputstream);
}
catch(Exception exception)
{
System.err.println("u4E0Du80FDu8BFBu53D6u5C5Eu6027u6587u4EF6.u8BF7u786Eu4FDDdb.propertiesu5728CLASSPATHu6307u5B9Au7684u8DEFu5F84u4E2D");
return null;
}
String s = properties.getProperty("logfile", "DBConnectionManager.log");
try
{
log = new PrintWriter(new FileWriter(s, true), true);
}
catch(IOException ioexception)
{
System.err.println("u65E0u6CD5u6253u5F00u65E5u5FD7u6587u4EF6: " + s);
log = new PrintWriter(System.err);
}
conn = createConnection(properties);
return conn;
}
private Connection createConnection(Properties properties)
{
for(Enumeration enumeration = properties.propertyNames(); enumeration.hasMoreElements();)
{
String s = (String)enumeration.nextElement();
if(s.endsWith(".url"))
{
String s1 = s.substring(0, s.lastIndexOf("."));
String s2 = properties.getProperty(s1 + ".url");
if(s2 == null)
{
log("u6CA1u6709u4E3Au8FDEu63A5u6C60" + s1 + "u6307u5B9AURL");
} else
{
String s3 = properties.getProperty("drivers");
String s4 = properties.getProperty(s1 + ".user");
String s5 = properties.getProperty(s1 + ".password");
String s6 = properties.getProperty(s1 + ".maxconn", "0");
int i;
try
{
i = Integer.valueOf(s6).intValue();
}
catch(NumberFormatException numberformatexception)
{
log("u9519u8BEFu7684u6700u5927u8FDEu63A5u6570u9650u5236: " + s6 + " .u8FDEu63A5u6C60: " + s1);
boolean flag = false;
}
log("u6210u529Fu521Bu5EFAu8FDEu63A5u6C60" + s1);
try
{
Class.forName(s3).newInstance();
Connection connection = DriverManager.getConnection(s2, s4, s5);
//log(new Date() + ":t" + "u6210u529Fu5EFAu7ACBu8FDEu7ED3");
return connection;
}
catch(Exception exception)
{
//log(new Date() + ":t" + "u65E0u6CD5u5EFAu7ACBu8FDEu7ED3(" + exception.toString() + ")");
}
}
}
}
return null;
}
private void log(String s)
{
//log.println(new Date() + ":t" + s);
}
public synchronized void release()
{
try
{
conn.close();
log("u5173u95EDu6240u6709u8FDEu7ED3uFF01");
log.close();
}
catch(SQLException sqlexception)
{
log("u65E0u6CD5u5173u95EDu8FDEu63A5u6C60u4E2Du7684u8FDEu63A5: (" + sqlexception.toString() + ")");
}
}
private static DBConnectionBean instance;
private PrintWriter log;
private Connection conn;
}
=============================
db.properties
drivers=com.microsoft.jdbc.sqlserver.SQLServerDriver
logfile=C:\WINNT\System32\log.txt
access.url=jdbc:microsoft:sqlserver:/
|
从错误的提示看应该是你不小心搞错了文件名或带.java的问题,但从你写程序来看,又应该不会不考虑这个问题的。既然错误是java.lang.NoClassDefFoundError: RecruitTypeDict,应改来说不会是程序的问题(请原谅,本人很懒,没看你的程序),个人觉得这个错误绝不会是程序的错(public class RecruitTypeDict这个和错误提示决定)。
请确认 Javac是否用错!
请确认 Javac是否用错!
|
程序没有出错!我帮你测过,我同意楼上的观点