我用的Eclipse开发工具写java代码,连接的是SQLServer2000。提示ResultSetisclosed代码如下:privatestaticvoidgetDBConnection(){try{Class.forName(strName);conn=DriverManager.ge...
我用的Eclipse开发工具写java代码,连接的是SQL Server 2000。提示ResultSet is closed
代码如下:
private static void getDBConnection() { try { Class.forName(strName); conn = DriverManager.getConnection(strURL); } catch (ClassNotFoundException e1) { // TODO: handle exception JOptionPane.showMessageDialog(null, "找不到数据库驱动程序类!\n"+e1,"提示", JOptionPane.ERROR_MESSAGE); } catch(SQLException e2){ System.out.println("getDBconnection() 1"); JOptionPane.showMessageDialog(null, "无法连接数据库!\n"+e2,"提示", JOptionPane.ERROR_MESSAGE); } } public static ArrayList getAllCar() { String strSQL = "select * from car"; //String strSQL = "select * from car1"; cars.clear(); try { getDBConnection(); statement =conn.createStatement(); rs = statement.executeQuery(strSQL); while(rs.next()){ Car car = new Car(); //CarType carType = new CarType(); car.setCarNo(rs.getInt(1)); car.setCarName(rs.getString(2)); car.setColor(rs.getString(3));
car.setCarTypeNo(rs.getInt(4)); //carType.setCarType(rs.getString(4)); car.setBid(rs.getFloat(5)); car.setPrice(rs.getFloat(6)); car.setCompany(rs.getString(7)); cars.add(car); } } catch (SQLException e) { // TODO: handle exception System.out.println(e); System.out.println("&&&&"); JOptionPane.showMessageDialog(null, "无法连接数据库!\n"+e,"错误", JOptionPane.ERROR_MESSAGE); }finally{ System.out.println("#"); close(); } return cars; }
展开