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

📄 databaseoperation.java

📁 人才招聘网站,该系统是从软件工程的角度的,以人才招聘网站的开发为例,详细介绍一个数据库应用系统的开发过程,介绍的人才系统使用SQL Server2000作为后台的数据管理系统,前端使用JDBC对象和数
💻 JAVA
字号:
package XiaoYuJob.util;

import java.sql.*;

/**
 *数据库操作类
 */
public class DataBaseOperation {

    private DataBaseConn con = new DataBaseConn();
    private Statement stmt;
    private ResultSet rs;

    /**
     *获得记录条数
     *output parameter: num = -2 ;Exception num = -1 ;Error
     *			num = 0  ;Nothing   num > 0  ;Right
     */
    public int getRowCount(String strSql) {
        int intCount = 0;
        try {
            stmt = con.getStmtread();
            rs = stmt.executeQuery("SELECT COUNT(*) FROM " + strSql);
            if (rs.next()) {
                intCount = rs.getInt(1);
            } else {
                intCount = -1;
            }
        } catch (Exception e) {
            intCount = -2;
            System.err.println(e.getMessage());
            e.printStackTrace();
        } finally {
            con.close();
            return intCount;
        }
    }
    /**
     *数据库插入操作
     *输入参数:	insert SQL
     *输出参数:	num = -2 >Exception num = 0  >nothing
     *			num > 1  right
     */
    public int insert(String sql) {
        int count = 0;
        stmt = con.getStmt();
        try {
            count = stmt.executeUpdate(sql);
        } catch (Exception e) {
            count = -2;
            System.err.println(e.getMessage());
            e.printStackTrace();
        } finally {
            con.close();
            return count;
        }
    }

    /**
     *数据库更新操作
     *输入参数:	update SQL
     *输出参数:	num = -2 >Exception num = 0  >nothing
     *			num > 1  right
     */
    public int update(String sql) {
        int count = 0;
        stmt = con.getStmt();
        try {
            count = stmt.executeUpdate(sql);
        } catch (Exception e) {
            count = -2;
            System.err.println(e.getMessage());
            e.printStackTrace();
        } finally {
            con.close();
            return count;
        }
    }

    /**
     *删除操作
     *输入参数:	delete SQL
     *输出参数:	count = -2 >Exception count = 0  >nothing
     *			count > 1  >right
     */
    public int delete(String sql) {
        int count = 0;
        stmt = con.getStmt();
        try {
            count = stmt.executeUpdate(sql);
        } catch (Exception e) {
            count = -2;
            System.err.println(e.getMessage());
            e.printStackTrace();
        } finally {
            con.close();
            return count;
        }
    }
}

⌨️ 快捷键说明

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