package com.abc.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class BaseDao {
 public Connection getConn()
 {
  Connection conn=null;
  try {
   Class.forName("com.mysql.jdbc.Driver");
  } catch (ClassNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  String url="jdbc:mysql://127.0.0.1:3306/user";
  try {
   conn=DriverManager.getConnection(url, "root", "");
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }  
  return conn;
 }
 public void closeAll(ResultSet rs,Statement stat,Connection conn)
 {
  if(rs!=null)
   try {
    rs.close();
   } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
  if(stat!=null)
   try {
    stat.close();
   } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
  if(conn!=null)
   try {
    conn.close();
   } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
 }
}

相关文章:

  • 2021-08-23
猜你喜欢
  • 2021-04-14
  • 2022-01-15
  • 2021-10-18
  • 2021-09-19
  • 2021-12-11
  • 2022-01-27
相关资源
相似解决方案