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

📄 mydboperater.java

📁 一个学校当中的教务管理系统
💻 JAVA
字号:
/*
 * MyDbOperater.java
 *
 * Created on 2007年7月27日, 下午10:08
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package dbclass;
import java.sql.*;
/**
 *
 * @author 徐翘
 */
public class MyDbOperater extends MyDbConnection{
    
    /** Creates a new instance of MyDbOperater */
    public MyDbOperater() throws SQLException
    {
    }
    
        public ResultSet executeQuery(String sql) throws SQLException{
            if(conn==null || conn.isClosed())
                makeConnection();
            Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
            //对于一般的查询操作,我们只要生成一个可流动的结果集就行了.
            //而对于在查询时要更新记录,我们用另一个业务方法来处理,这样,
            //这样可以在普通查询时节省回滚空间.
            ResultSet rs = stmt.executeQuery(sql);
            return rs;
        }
        
        public ResultSet executeUpdatabledQuery(String sql) throws SQLException{
            if (conn == null || conn.isClosed())
                makeConnection();
            Statement stmt = conn.createStatement(
                    ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_UPDATABLE);
            //可更新的结果结要更大的回滚空间,普通查询时不要调用这个方法
            ResultSet rs = stmt.executeQuery(sql);
            return rs;
        }
     public int executeUpdate(String sql) throws SQLException{
            if (conn == null || conn.isClosed()) 
                makeConnection();
            Statement stmt = conn.createStatement();
            //这个stmt在执行更新操作时更加节省内存,永远记住,能节省的时候要节省
            //每一个字节的内存,虽然硬件设备可能会有很大的物理内存,但内存是给用
            //户用的而不是给程序员用的(!!!!!!!!!!!!!!!!!!)
            int s = stmt.executeUpdate(sql);
            return s;
        }
      public PreparedStatement getPreparedStmt(String sql) throws SQLException{
            if (conn == null || conn.isClosed()) 
                makeConnection();
            PreparedStatement ps = conn.prepareStatement(sql);
            return ps;
        }
       public CallableStatement getCallableStmt(String sql) throws SQLException{
            if (conn == null || conn.isClosed()) 
                makeConnection();
            CallableStatement cs= conn.prepareCall(sql);
            return cs;
        }
}

⌨️ 快捷键说明

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