public DbOperator() throws SQLException, ClassNotFoundException{
conn = null;
stmt = null;
rs = null;
/* Microsoft Sql Server 的驱动程序 需要把三个jar外部文件msbase.jar, 
 * msutil.jar, mssqlserver.jar导入程序
 */
driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
url = "jdbc:microsoft:sqlserver://localhost:1433;databaseName=oldproduct";
strUser = "aaaaa";
strPwd = "123456";
/*装载数据库驱动程序*/
Class.forName(driver);
/*获得数据库连接对象*/
conn = DriverManager.getConnection(url,strUser,strPwd);
}
这个是一个构造方法
/**数据库断开连接**/
public void closDb() throws SQLException {
if(rs != null) { rs.close(); rs = null;}
if(stmt != null) {stmt.close(); stmt = null;}
if(conn != null) { conn.close(); conn = null;}
}
数据库连接不会有错的
我有一个插入数据库的方法都可以的

解决方案 »

  1.   

    你……传回rs的话一定不行的——bean被destroy的时候那个rs的连接也会被关闭。找个别的类封装一下——只传数值的话是没问题的。
      

  2.   

    将if(rs.next())改成while(rs.next())试一下,还有你抛的异常到底是什么?
    ***************************
    ? 1 ?: '*' ????????
      

  3.   

    watcher_shen(吉吾) 
    你能不能给我写一段代码
    我真的不知道什么地方错了
    我试了好几个方法了
      

  4.   

    你把
    rs=db.exeQuery(sql);
    这句用
    public ResultSet exeQuery(String strSql) throws SQLException
    里的代码直接替换掉试试