⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basedao.java

📁 功能强大
💻 JAVA
字号:
package Dao;

import java.sql.*;


/**
 * 数据库、连接、关闭
 * @author Administrator
 *
 */
public class BaseDao implements IconStr {

	/**
	 * 取得数据库连接
	 * @return Connection
	 * @throws SQLException
	 * @throws Exception
	 */
	public Connection getConnection()throws SQLException,Exception{
		Class.forName(this.DRIVER);
		Connection con=DriverManager.getConnection(this.CON_STR,this.UID,this.PWD);
		return con;
	}
	/**
	 * 关闭连接
	 * @param con
	 * @param st
	 * @param rs
	 */
	public void closeAll(Connection con,Statement st,ResultSet rs){
		if(rs!=null){
			try {rs.close();} catch (Exception e) {e.printStackTrace();}
		}
		if(st!=null){
			try {st.close();} catch (Exception e) {e.printStackTrace();}
		}
		if(con!=null){
			try {con.close();} catch (Exception e) {e.printStackTrace();}
		}
	}
	/**
	 * 增删改通用
	 * @param sql
	 * @return int
	 */
	public int exeZSG(String sql){
		int i=-1;
		Connection con=null;
		Statement st=null;
		try {
			con=this.getConnection();
			st=con.createStatement();
			i=st.executeUpdate(sql);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			this.closeAll(con, st, null);
		}
		return i;
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -