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

📄 database.java

📁 一个JAVA学习型BBS
💻 JAVA
字号:
package blog;

import java.sql.*;
import java.io.*;
import javax.sql.*;
import javax.naming.*;

public class DataBase 
{
   private Connection conn = null;
   private Statement stmt = null;
   public DataBase () 
   {
      try 
      {
         conn = (CP.ConnPool.getInstance()).getConnection();
         stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
      }
      catch(Exception ex) 
      {
         ex.printStackTrace();
      }
   }
   public Connection getconn(){
   	return this.conn;
   }
   public ResultSet executeQuery(String sql) throws SQLException 
   {
      return stmt.executeQuery(sql);
   }
   public boolean executeUpdate(String sql) throws SQLException 
   {
      boolean bupdate = false;
      int rowCount = stmt.executeUpdate(sql);
      //如果不成功,bupdate就会返回0
      if(rowCount != 0) 
         bupdate = true;
      return bupdate;
   }
   /**
    * ISO8859ToGBK
    * @param s8859 String
    * @return String
    */
   public static String ISO8859ToGBK(String s8859) 
   {
      String back = null;
      if(s8859 != null) 
      {
         try 
         {
            byte abyte0[] = s8859.getBytes("GBK");
            back = new String(abyte0);
         }
         catch(Exception e) 
         {
         }
      }
      else 
         back = "";
      return back;
   }
   /**
    * GBKToISO8859
    * @param sk String
    * @return String
    */
   public static String GBKToISO8859(String sk) 
   {
      String back = null;
      if(sk != null) 
      {
         try 
         {
            byte abyte0[] = sk.getBytes("8859_1");
            back = new String(abyte0);
         }
         catch(Exception e) 
         {
         }
      }
      else 
         back = "";
      return back;
   }
   public void Commit() throws SQLException
   {
      if(conn != null) 
         conn.commit();
   }
   public void RollBack() throws SQLException
   {
      if(conn != null) 
         conn.rollback();
   }
   public void free() 
   {
      try 
      {
         if(conn != null) 
            conn.close();
      }
      catch(Exception ex) 
      {
      }
   }
}

⌨️ 快捷键说明

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