ii

package com.neusoft.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DbUtils 
{
 private DbUtils(){}
 private static Connection conn;
 public static Connection getConnection()
 {
  try 
  {
   DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
   //2.连接数据库,获取数据库连接对象
   String url="jdbc:oracle:thin:@zhangyahui:1521:oracle";
   String user="scott";
   String password="0000";
   conn=DriverManager.getConnection(url,user,password);
  } catch (SQLException e) 
  {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return conn;
  }
 public static  void closeConnection()
 {
  try {
   if(conn!=null)
   {
    conn.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } 
 }
 public static void closeStatement(Statement stmt)
 {
  try {
   if(stmt!=null)
   {
    stmt.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  }
 public static void closeResultSet(ResultSet rs)
 {
  //4.关闭数据库
  try {
   if(rs!=null)
   {
    rs.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  }
}
 
 
 
 
 
package com.neusoft.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DbUtils 
{
 private DbUtils(){}
 private static Connection conn;
 public static Connection getConnection()
 {
  try 
  {
   DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
   //2.连接数据库,获取数据库连接对象
   String url="jdbc:oracle:thin:@zhangyahui:1521:oracle";
   String user="scott";
   String password="0000";
   conn=DriverManager.getConnection(url,user,password);
  } catch (SQLException e) 
  {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return conn;
  }
 public static  void closeConnection()
 {
  try {
   if(conn!=null)
   {
    conn.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } 
 }
 public static void closeStatement(Statement stmt)
 {
  try {
   if(stmt!=null)
   {
    stmt.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  }
 public static void closeResultSet(ResultSet rs)
 {
  //4.关闭数据库
  try {
   if(rs!=null)
   {
    rs.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  }
}







package com.neusoft.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
//实现类
public class DeptDaoImpl implements DeptDaoInterface {
 @Override
 public void deleteDept(int deptno) {
  // TODO Auto-generated method stub
  PreparedStatement pstmt=null;
  Dept dept=new Dept();
  try{
  Connection conn=DbUtils.getConnection();
  String sql="delete from forjava where ID=?";
  pstmt=conn.prepareStatement(sql);
  pstmt.setInt(1, deptno);
      //pstmt=conn.prepareStatement(sql);
  pstmt.executeUpdate();
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
 }
 @Override
 public List<Dept> getAllDepts() {
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  List<Dept> depts=new ArrayList<Dept>();
  try{
  Connection conn=DbUtils.getConnection();
  String sql="select * from forjava";
      pstmt=conn.prepareStatement(sql);
     rs= pstmt.executeQuery();
  while(rs.next())
  {
   Dept dept=new Dept();
   dept.setID(rs.getInt("ID"));
   dept.setName(rs.getString("NAME"));
   System.out.println(rs.getInt("ID")+"    "+rs.getString("NAME"));
   depts.add(dept);
  }
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   DbUtils.closeResultSet(rs);
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
  return depts;
 }
 @Override
 public Dept getDeptByDeptNo(int deptno) {
  // TODO Auto-generated method stub
  return null;
 }
 @Override
 public void insertDept(Dept dept) {
  // TODO Auto-generated method stub
  PreparedStatement pstmt=null;
  
  try{
  Connection conn=DbUtils.getConnection();
  String sql="insert into forjava(ID,name) values(?,?)";
      pstmt=conn.prepareStatement(sql);
    
      pstmt.setInt(1, dept.getID());
      pstmt.setString(2, dept.getName());
      
      pstmt.executeUpdate();
      
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
 }
 @Override
 public void updateDept(Dept dept) {
  // TODO Auto-generated method stub
  
 }
}
 
 
 
 
 
package com.neusoft.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DbUtils 
{
 private DbUtils(){}
 private static Connection conn;
 public static Connection getConnection()
 {
  try 
  {
   DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
   //2.连接数据库,获取数据库连接对象
   String url="jdbc:oracle:thin:@zhangyahui:1521:oracle";
   String user="scott";
   String password="0000";
   conn=DriverManager.getConnection(url,user,password);
  } catch (SQLException e) 
  {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return conn;
  }
 public static  void closeConnection()
 {
  try {
   if(conn!=null)
   {
    conn.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } 
 }
 public static void closeStatement(Statement stmt)
 {
  try {
   if(stmt!=null)
   {
    stmt.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  }
 public static void closeResultSet(ResultSet rs)
 {
  //4.关闭数据库
  try {
   if(rs!=null)
   {
    rs.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  }
}





package com.neusoft.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DbUtils 
{
 private DbUtils(){}
 private static Connection conn;
 public static Connection getConnection()
 {
  try 
  {
   DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
   //2.连接数据库,获取数据库连接对象
   String url="jdbc:oracle:thin:@zhangyahui:1521:oracle";
   String user="scott";
   String password="0000";
   conn=DriverManager.getConnection(url,user,password);
  } catch (SQLException e) 
  {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return conn;
  }
 public static  void closeConnection()
 {
  try {
   if(conn!=null)
   {
    conn.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } 
 }
 public static void closeStatement(Statement stmt)
 {
  try {
   if(stmt!=null)
   {
    stmt.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  }
 public static void closeResultSet(ResultSet rs)
 {
  //4.关闭数据库
  try {
   if(rs!=null)
   {
    rs.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  }
}







package com.neusoft.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
//实现类
public class DeptDaoImpl implements DeptDaoInterface {
 @Override
 public void deleteDept(int deptno) {
  // TODO Auto-generated method stub
  PreparedStatement pstmt=null;
  Dept dept=new Dept();
  try{
  Connection conn=DbUtils.getConnection();
  String sql="delete from forjava where ID=?";
  pstmt=conn.prepareStatement(sql);
  pstmt.setInt(1, deptno);
      //pstmt=conn.prepareStatement(sql);
  pstmt.executeUpdate();
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
 }
 @Override
 public List<Dept> getAllDepts() {
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  List<Dept> depts=new ArrayList<Dept>();
  try{
  Connection conn=DbUtils.getConnection();
  String sql="select * from forjava";
      pstmt=conn.prepareStatement(sql);
     rs= pstmt.executeQuery();
  while(rs.next())
  {
   Dept dept=new Dept();
   dept.setID(rs.getInt("ID"));
   dept.setName(rs.getString("NAME"));
   System.out.println(rs.getInt("ID")+"    "+rs.getString("NAME"));
   depts.add(dept);
  }
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   DbUtils.closeResultSet(rs);
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
  return depts;
 }
 @Override
 public Dept getDeptByDeptNo(int deptno) {
  // TODO Auto-generated method stub
  return null;
 }
 @Override
 public void insertDept(Dept dept) {
  // TODO Auto-generated method stub
  PreparedStatement pstmt=null;
  
  try{
  Connection conn=DbUtils.getConnection();
  String sql="insert into forjava(ID,name) values(?,?)";
      pstmt=conn.prepareStatement(sql);
    
      pstmt.setInt(1, dept.getID());
      pstmt.setString(2, dept.getName());
      
      pstmt.executeUpdate();
      
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
 }
 @Override
 public void updateDept(Dept dept) {
  // TODO Auto-generated method stub
  
 }
}









import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
//实现类
public class DeptDaoImpl implements DeptDaoInterface {
 @Override
 public void deleteDept(int deptno) {
  // TODO Auto-generated method stub
  PreparedStatement pstmt=null;
  Dept dept=new Dept();
  try{
  Connection conn=DbUtils.getConnection();
  String sql="delete from forjava where ID=?";
  pstmt=conn.prepareStatement(sql);
  pstmt.setInt(1, deptno);
      //pstmt=conn.prepareStatement(sql);
  pstmt.executeUpdate();
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
 }
 @Override
 public List<Dept> getAllDepts() {
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  List<Dept> depts=new ArrayList<Dept>();
  try{
  Connection conn=DbUtils.getConnection();
  String sql="select * from forjava";
      pstmt=conn.prepareStatement(sql);
     rs= pstmt.executeQuery();
  while(rs.next())
  {
   Dept dept=new Dept();
   dept.setID(rs.getInt("ID"));
   dept.setName(rs.getString("NAME"));
   System.out.println(rs.getInt("ID")+"    "+rs.getString("NAME"));
   depts.add(dept);
  }
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   DbUtils.closeResultSet(rs);
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
  return depts;
 }
 @Override
 public Dept getDeptByDeptNo(int deptno) {
  // TODO Auto-generated method stub
  return null;
 }
 @Override
 public void insertDept(Dept dept) {
  // TODO Auto-generated method stub
  PreparedStatement pstmt=null;
  
  try{
  Connection conn=DbUtils.getConnection();
  String sql="insert into forjava(ID,name) values(?,?)";
      pstmt=conn.prepareStatement(sql);
    
      pstmt.setInt(1, dept.getID());
      pstmt.setString(2, dept.getName());
      
      pstmt.executeUpdate();
      
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
 }
 @Override
 public void updateDept(Dept dept) {
  // TODO Auto-generated method stub
  
 }
}

package com.neusoft.dao;
import java.util.List;
//接口
public interface DeptDaoInterface {
List<Dept> getAllDepts();
void insertDept(Dept dept);
void updateDept(Dept dept);
void deleteDept(int deptno);
Dept getDeptByDeptNo(int deptno);
}
 
 
 
 
 
 
package com.neusoft.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DbUtils 
{
 private DbUtils(){}
 private static Connection conn;
 public static Connection getConnection()
 {
  try 
  {
   DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
   //2.连接数据库,获取数据库连接对象
   String url="jdbc:oracle:thin:@zhangyahui:1521:oracle";
   String user="scott";
   String password="0000";
   conn=DriverManager.getConnection(url,user,password);
  } catch (SQLException e) 
  {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return conn;
  }
 public static  void closeConnection()
 {
  try {
   if(conn!=null)
   {
    conn.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } 
 }
 public static void closeStatement(Statement stmt)
 {
  try {
   if(stmt!=null)
   {
    stmt.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  }
 public static void closeResultSet(ResultSet rs)
 {
  //4.关闭数据库
  try {
   if(rs!=null)
   {
    rs.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  }
}





package com.neusoft.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DbUtils 
{
 private DbUtils(){}
 private static Connection conn;
 public static Connection getConnection()
 {
  try 
  {
   DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
   //2.连接数据库,获取数据库连接对象
   String url="jdbc:oracle:thin:@zhangyahui:1521:oracle";
   String user="scott";
   String password="0000";
   conn=DriverManager.getConnection(url,user,password);
  } catch (SQLException e) 
  {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return conn;
  }
 public static  void closeConnection()
 {
  try {
   if(conn!=null)
   {
    conn.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } 
 }
 public static void closeStatement(Statement stmt)
 {
  try {
   if(stmt!=null)
   {
    stmt.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  }
 public static void closeResultSet(ResultSet rs)
 {
  //4.关闭数据库
  try {
   if(rs!=null)
   {
    rs.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  }
}







package com.neusoft.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
//实现类
public class DeptDaoImpl implements DeptDaoInterface {
 @Override
 public void deleteDept(int deptno) {
  // TODO Auto-generated method stub
  PreparedStatement pstmt=null;
  Dept dept=new Dept();
  try{
  Connection conn=DbUtils.getConnection();
  String sql="delete from forjava where ID=?";
  pstmt=conn.prepareStatement(sql);
  pstmt.setInt(1, deptno);
      //pstmt=conn.prepareStatement(sql);
  pstmt.executeUpdate();
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
 }
 @Override
 public List<Dept> getAllDepts() {
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  List<Dept> depts=new ArrayList<Dept>();
  try{
  Connection conn=DbUtils.getConnection();
  String sql="select * from forjava";
      pstmt=conn.prepareStatement(sql);
     rs= pstmt.executeQuery();
  while(rs.next())
  {
   Dept dept=new Dept();
   dept.setID(rs.getInt("ID"));
   dept.setName(rs.getString("NAME"));
   System.out.println(rs.getInt("ID")+"    "+rs.getString("NAME"));
   depts.add(dept);
  }
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   DbUtils.closeResultSet(rs);
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
  return depts;
 }
 @Override
 public Dept getDeptByDeptNo(int deptno) {
  // TODO Auto-generated method stub
  return null;
 }
 @Override
 public void insertDept(Dept dept) {
  // TODO Auto-generated method stub
  PreparedStatement pstmt=null;
  
  try{
  Connection conn=DbUtils.getConnection();
  String sql="insert into forjava(ID,name) values(?,?)";
      pstmt=conn.prepareStatement(sql);
    
      pstmt.setInt(1, dept.getID());
      pstmt.setString(2, dept.getName());
      
      pstmt.executeUpdate();
      
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
 }
 @Override
 public void updateDept(Dept dept) {
  // TODO Auto-generated method stub
  
 }
}






package com.neusoft.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DbUtils 
{
 private DbUtils(){}
 private static Connection conn;
 public static Connection getConnection()
 {
  try 
  {
   DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
   //2.连接数据库,获取数据库连接对象
   String url="jdbc:oracle:thin:@zhangyahui:1521:oracle";
   String user="scott";
   String password="0000";
   conn=DriverManager.getConnection(url,user,password);
  } catch (SQLException e) 
  {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return conn;
  }
 public static  void closeConnection()
 {
  try {
   if(conn!=null)
   {
    conn.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } 
 }
 public static void closeStatement(Statement stmt)
 {
  try {
   if(stmt!=null)
   {
    stmt.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  }
 public static void closeResultSet(ResultSet rs)
 {
  //4.关闭数据库
  try {
   if(rs!=null)
   {
    rs.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  }
}





package com.neusoft.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DbUtils 
{
 private DbUtils(){}
 private static Connection conn;
 public static Connection getConnection()
 {
  try 
  {
   DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
   //2.连接数据库,获取数据库连接对象
   String url="jdbc:oracle:thin:@zhangyahui:1521:oracle";
   String user="scott";
   String password="0000";
   conn=DriverManager.getConnection(url,user,password);
  } catch (SQLException e) 
  {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return conn;
  }
 public static  void closeConnection()
 {
  try {
   if(conn!=null)
   {
    conn.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } 
 }
 public static void closeStatement(Statement stmt)
 {
  try {
   if(stmt!=null)
   {
    stmt.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  }
 public static void closeResultSet(ResultSet rs)
 {
  //4.关闭数据库
  try {
   if(rs!=null)
   {
    rs.close();
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  }
}







package com.neusoft.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
//实现类
public class DeptDaoImpl implements DeptDaoInterface {
 @Override
 public void deleteDept(int deptno) {
  // TODO Auto-generated method stub
  PreparedStatement pstmt=null;
  Dept dept=new Dept();
  try{
  Connection conn=DbUtils.getConnection();
  String sql="delete from forjava where ID=?";
  pstmt=conn.prepareStatement(sql);
  pstmt.setInt(1, deptno);
      //pstmt=conn.prepareStatement(sql);
  pstmt.executeUpdate();
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
 }
 @Override
 public List<Dept> getAllDepts() {
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  List<Dept> depts=new ArrayList<Dept>();
  try{
  Connection conn=DbUtils.getConnection();
  String sql="select * from forjava";
      pstmt=conn.prepareStatement(sql);
     rs= pstmt.executeQuery();
  while(rs.next())
  {
   Dept dept=new Dept();
   dept.setID(rs.getInt("ID"));
   dept.setName(rs.getString("NAME"));
   System.out.println(rs.getInt("ID")+"    "+rs.getString("NAME"));
   depts.add(dept);
  }
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   DbUtils.closeResultSet(rs);
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
  return depts;
 }
 @Override
 public Dept getDeptByDeptNo(int deptno) {
  // TODO Auto-generated method stub
  return null;
 }
 @Override
 public void insertDept(Dept dept) {
  // TODO Auto-generated method stub
  PreparedStatement pstmt=null;
  
  try{
  Connection conn=DbUtils.getConnection();
  String sql="insert into forjava(ID,name) values(?,?)";
      pstmt=conn.prepareStatement(sql);
    
      pstmt.setInt(1, dept.getID());
      pstmt.setString(2, dept.getName());
      
      pstmt.executeUpdate();
      
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
 }
 @Override
 public void updateDept(Dept dept) {
  // TODO Auto-generated method stub
  
 }
}









import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
//实现类
public class DeptDaoImpl implements DeptDaoInterface {
 @Override
 public void deleteDept(int deptno) {
  // TODO Auto-generated method stub
  PreparedStatement pstmt=null;
  Dept dept=new Dept();
  try{
  Connection conn=DbUtils.getConnection();
  String sql="delete from forjava where ID=?";
  pstmt=conn.prepareStatement(sql);
  pstmt.setInt(1, deptno);
      //pstmt=conn.prepareStatement(sql);
  pstmt.executeUpdate();
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
 }
 @Override
 public List<Dept> getAllDepts() {
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  List<Dept> depts=new ArrayList<Dept>();
  try{
  Connection conn=DbUtils.getConnection();
  String sql="select * from forjava";
      pstmt=conn.prepareStatement(sql);
     rs= pstmt.executeQuery();
  while(rs.next())
  {
   Dept dept=new Dept();
   dept.setID(rs.getInt("ID"));
   dept.setName(rs.getString("NAME"));
   System.out.println(rs.getInt("ID")+"    "+rs.getString("NAME"));
   depts.add(dept);
  }
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   DbUtils.closeResultSet(rs);
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
  return depts;
 }
 @Override
 public Dept getDeptByDeptNo(int deptno) {
  // TODO Auto-generated method stub
  return null;
 }
 @Override
 public void insertDept(Dept dept) {
  // TODO Auto-generated method stub
  PreparedStatement pstmt=null;
  
  try{
  Connection conn=DbUtils.getConnection();
  String sql="insert into forjava(ID,name) values(?,?)";
      pstmt=conn.prepareStatement(sql);
    
      pstmt.setInt(1, dept.getID());
      pstmt.setString(2, dept.getName());
      
      pstmt.executeUpdate();
      
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
 }
 @Override
 public void updateDept(Dept dept) {
  // TODO Auto-generated method stub
  
 }
}

package com.neusoft.dao;
import java.util.List;
//接口
public interface DeptDaoInterface {
List<Dept> getAllDepts();
void insertDept(Dept dept);
void updateDept(Dept dept);
void deleteDept(int deptno);
Dept getDeptByDeptNo(int deptno);
}









import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
//实现类
public class DeptDaoImpl implements DeptDaoInterface {
 @Override
 public void deleteDept(int deptno) {
  // TODO Auto-generated method stub
  PreparedStatement pstmt=null;
  Dept dept=new Dept();
  try{
  Connection conn=DbUtils.getConnection();
  String sql="delete from forjava where ID=?";
  pstmt=conn.prepareStatement(sql);
  pstmt.setInt(1, deptno);
      //pstmt=conn.prepareStatement(sql);
  pstmt.executeUpdate();
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
 }
 @Override
 public List<Dept> getAllDepts() {
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  List<Dept> depts=new ArrayList<Dept>();
  try{
  Connection conn=DbUtils.getConnection();
  String sql="select * from forjava";
      pstmt=conn.prepareStatement(sql);
     rs= pstmt.executeQuery();
  while(rs.next())
  {
   Dept dept=new Dept();
   dept.setID(rs.getInt("ID"));
   dept.setName(rs.getString("NAME"));
   System.out.println(rs.getInt("ID")+"    "+rs.getString("NAME"));
   depts.add(dept);
  }
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   DbUtils.closeResultSet(rs);
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
  return depts;
 }
 @Override
 public Dept getDeptByDeptNo(int deptno) {
  // TODO Auto-generated method stub
  return null;
 }
 @Override
 public void insertDept(Dept dept) {
  // TODO Auto-generated method stub
  PreparedStatement pstmt=null;
  
  try{
  Connection conn=DbUtils.getConnection();
  String sql="insert into forjava(ID,name) values(?,?)";
      pstmt=conn.prepareStatement(sql);
    
      pstmt.setInt(1, dept.getID());
      pstmt.setString(2, dept.getName());
      
      pstmt.executeUpdate();
      
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
 }
 @Override
 public void updateDept(Dept dept) {
  // TODO Auto-generated method stub
  
 }
}

import java.util.List;
//接口
public interface DeptDaoInterface {
List<Dept> getAllDepts();
void insertDept(Dept dept);
void updateDept(Dept dept);
void deleteDept(int deptno);
Dept getDeptByDeptNo(int deptno);
}
package com.neusoft.dao;
//package com.neusoft.dao;
//实体类
public class Dept {
private int ID;
private String name;
public Dept(int de,String dna){
 this.ID=de;
 this.name=dna;
}
public Dept()
{
 
}
public int getID() {
 return ID;
}
public void setID(int iD) {
 ID = iD;
}
public String getName() {
 return name;
}
public void setName(String name) {
 this.name = name;
}
}
 
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
//实现类
public class DeptDaoImpl implements DeptDaoInterface {
 @Override
 public void deleteDept(int deptno) {
  // TODO Auto-generated method stub
  PreparedStatement pstmt=null;
  Dept dept=new Dept();
  try{
  Connection conn=DbUtils.getConnection();
  String sql="delete from forjava where ID=?";
  pstmt=conn.prepareStatement(sql);
  pstmt.setInt(1, deptno);
      //pstmt=conn.prepareStatement(sql);
  pstmt.executeUpdate();
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
 }
 @Override
 public List<Dept> getAllDepts() {
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  List<Dept> depts=new ArrayList<Dept>();
  try{
  Connection conn=DbUtils.getConnection();
  String sql="select * from forjava";
      pstmt=conn.prepareStatement(sql);
     rs= pstmt.executeQuery();
  while(rs.next())
  {
   Dept dept=new Dept();
   dept.setID(rs.getInt("ID"));
   dept.setName(rs.getString("NAME"));
   System.out.println(rs.getInt("ID")+"    "+rs.getString("NAME"));
   depts.add(dept);
  }
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   DbUtils.closeResultSet(rs);
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
  return depts;
 }
 @Override
 public Dept getDeptByDeptNo(int deptno) {
  // TODO Auto-generated method stub
  return null;
 }
 @Override
 public void insertDept(Dept dept) {
  // TODO Auto-generated method stub
  PreparedStatement pstmt=null;
  
  try{
  Connection conn=DbUtils.getConnection();
  String sql="insert into forjava(ID,name) values(?,?)";
      pstmt=conn.prepareStatement(sql);
    
      pstmt.setInt(1, dept.getID());
      pstmt.setString(2, dept.getName());
      
      pstmt.executeUpdate();
      
  }catch(SQLException ex)
  {
   ex.printStackTrace();
  }finally
  {
   
   DbUtils.closeStatement(pstmt);
   DbUtils.closeConnection();
  
  }
 }
 @Override
 public void updateDept(Dept dept) {
  // TODO Auto-generated method stub
  
 }
}
 
import java.util.List;
//接口
public interface DeptDaoInterface {
List<Dept> getAllDepts();
void insertDept(Dept dept);
void updateDept(Dept dept);
void deleteDept(int deptno);
Dept getDeptByDeptNo(int deptno);
}
//package com.neusoft.dao;
//实体类
public class Dept {
private int ID;
private String name;
public Dept(int de,String dna){
 this.ID=de;
 this.name=dna;
}
public Dept()
{
 
}
public int getID() {
 return ID;
}
public void setID(int iD) {
 ID = iD;
}
public String getName() {
 return name;
}
public void setName(String name) {
 this.name = name;
}
}
 
 
 
 
 
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值