dboperation.java

来自「基于java的医院门诊管理系统」· Java 代码 · 共 80 行

JAVA
80
字号
package crqs.dboperation;

import java.sql.*;

public abstract class DBOperation {

	protected String userName;

	protected String password;

	protected Connection conn;

	protected Statement stmt;

	protected ResultSet result;

	protected DBOperation() {
	}
	
	public String getUserName(){
		return userName;
	}
	
	public void setUserName(String un){
		this.userName=un;
	}
	
	public String getPassword(){
		return password;
	}
	
	public void setPasswd(String p){
		this.password=p;
	}

	protected DBOperation(String un, String pw) {
		this.userName = un;
		this.password = pw;
	}

	public ResultSet getResult() {
		return result;
	}
	
	public abstract boolean setPassword(String old, String newPw) throws SQLException ;

	public synchronized void closeConnection() {
		if (stmt != null)
			try {
				stmt.close();
				stmt = null;
			} catch (SQLException e) {
				e.printStackTrace();
			}
		if (conn != null)
			try {
				conn.close();
				conn = null;
			} catch (SQLException e) {
				e.printStackTrace();
			}
	}

	protected synchronized void executeQuery(String sqlStr) throws SQLException {
		if (conn == null) {
			conn = DBConnection.getConnection();
			stmt = conn.createStatement();
		}
		result = stmt.executeQuery(sqlStr);
	}

	protected synchronized int executeUpdate(String sqlStr) throws SQLException {
		if (conn == null) {
			conn = DBConnection.getConnection();
			stmt = conn.createStatement();
		}
		return stmt.executeUpdate(sqlStr);
	}
}

⌨️ 快捷键说明

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