下面是我定义的一个javabean用来连接数据库package EnterpriseManagement.util;import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;import EnterpriseManagement.load.employee;public class OracleUtil {
private String dataSourceName;
private DataSource ds;
private Connection conn;
private PreparedStatement pstmt; public OracleUtil(String dataSourceName) {
this.dataSourceName = dataSourceName;
} public OracleUtil() {
} public void setDataSourceName(String dataSourceName) {
this.dataSourceName = dataSourceName;
} public void init() {
try {
InitialContext context = new InitialContext();
ds = (DataSource)context.lookup(dataSourceName);
conn = ds.getConnection();
} catch (NamingException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}

public ResultSet query(String sql) {
ResultSet result = null;
try {
pstmt = conn.prepareStatement(sql);
result = pstmt.executeQuery();
} catch (SQLException e) {
e.printStackTrace();
}
return result;
} public boolean IDIN(String sql, String id) {
ResultSet set = query(sql);
try {
while (set.next()) {
employee e = (employee) set;
if (id.equalsIgnoreCase(e.getId())) {
return true;
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
} public boolean PasswordIN(String sql, String id, String pwd) {
ResultSet set = query(sql);
try {
while (set.next()) {
employee e = (employee) set;
if (id.equalsIgnoreCase(e.getId())
&& pwd.equalsIgnoreCase(e.getPwd())) {
return true;
} else {
return false;
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
public void close(){
try {
pstmt.close();
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}下面是我调用javabean的部分代码实现验证用户名密码都正确登录的问题OracleUtil db = new OracleUtil("java:/comp/env/jdbc/oracleds");
db.init();
if (db.IDIN(sql, id)) {
db.close();
if (db.PasswordIN(sql, id, pwd)) {
db.close();
message = "登录成功";
} else {
message = "密码错误,请重新输入";
}
} else {
message = "用户名不存在";
}期中数据库便没有错误,tomcat在其他项目中也正常,现在的问题就是连不上数据库,请高手指教,谢谢。