sqlserver2000数据库连接问题

来源:百度知道 编辑:UC知道 时间:2024/06/24 14:03:13
急急急!
Connection con=null;
Statement stmt=null;
try{

System.out.println("test");

con = DBConnectionFactory.getConnection("wjpkc");
System.out.println("加载驱动成功");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
System.out.println("ok!数据库连接成功");
}catch(org.apache.commons.dbcp.SQLNestedException ee){ //连接池耗尽
out.println("数据库连接繁忙,连接池耗尽,稍后重试!");
}catch(SQLException sqle){
out.println("数据库操作失败!");
}catch(Exception e){
out.println("操作失败,未知错误!");
}finally{
//释放连接
DBConnectionFactory.closeRes(stmt);
DBConnectionFactory.closeRes(con);
}
%>

但是输出只有:test
且运行jsp页面时候输出:数据库操作失败!
也就是说加载驱动失败
到底怎么回事呢?

建立连接时的参数只有一个吗

你写的这个DBConnectionFactory方法里面的连接对象可能错了。
发出来看看。你这个是连接什么数据库

public class Base {
private Connection con;
public Connection getConn() throws ClassNotFoundException, SQLException{
//加载驱动
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//建立连接
con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=Company","sa","sa");
return con;
}
public void closeObject(ResultSet rs,PreparedStatement ps,Connection con) throws SQLException{
if(rs!=null){
rs.close();
}
if(ps!=null){
ps.close();
}
if(con!=null){
con.close();
}
}
}

public class UserDAO extends Base{
//翻页的方法
public ArrayList<newInfo> getSelectInfo(int index){
ArrayList<newInfo> list=new ArrayList<newInfo>();
C