Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: ja
请问各位大侠,Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
com.datang.exception.ApplicationException是什么原因呢?烦请高手指导指导。一下是出错的代码:
package com.datang.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import
java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.datang.dao.EmployeeDAO;
import com.datang.exception.ApplicationException;
import com.datang.po.Employee;
import com.datang.po.EmployeeList;
import com.datang.util.DBUtil;
public class EmployeeMySQLDAOImpl implements EmployeeDAO{
public static final String GET_EMPLOYEE_BY_ID="select id,name,sex,hire_date,position,birthday,degree,major,experience
from t_employee";
public EmployeeList getEmployeeById(String id)throws ApplicationException{
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
EmployeeList emp=new EmployeeList();
try{
conn=DBUtil.getConnection(); <-----从这一句就直接跳转的finally里边了。。
pstmt=conn.prepareStatement(GET_EMPLOYEE_BY_ID);
pstmt.setString(1, id);
rs=pstmt.executeQuery();
while(rs.next()){
emp.setId(rs.getString(1));
emp.setName(rs.getString(2));
emp.setSex(rs.getString(3).equals("0")?"男":"女");
emp.setHire_date(rs.getDate(4));
emp.setPosition(rs.getString(5));
emp.setBirthday(rs.getDate(6));
emp.setDegree(rs.getString(7));
emp.setMajor(rs.getString(8));
emp.setExperience(rs.getString(9));
}
return emp;
}catch(
SQLException e){
e.printStackTrace();
return null;
}finally{
DBUtil.close(rs, pstmt, conn);
}
}
public static void main(String[] args){
try {
EmployeeList name=new EmployeeMySQLDAOImpl().getEmployeeById("1");
System.out.println(name);
} catch (ApplicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
抛出的异常是:2008-10-24 09:42:45:INFO main com.datang.util.DBUtil - 数据库发生异常Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
com.datang.exception.ApplicationException
at com.datang.util.DBUtil.getConnection(DBUtil.java:32)
at com.datang.dao.impl.EmployeeMySQLDAOImpl.getEmployeeById(EmployeeMySQLDAOImpl.java:166)
at com.datang.dao.impl.EmployeeMySQLDAOImpl.main(EmployeeMySQLDAOImpl.java:193)
经检查DBUtil.java ApplicationException.java 都没错,谢谢了!!
------解决方案--------------------java.naming.factory.initial
那一句跳了,你就再跟进去呗,应该是Class.forName那里出错了,检查一下。