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

📄 db.java

📁 现今的社会是一个信息飞速发达的社会
💻 JAVA
字号:
package numb1.com;

import java.lang.*;
import java.sql.*;


public class db{

  private Connection con;
  private Statement st;
  private ResultSet rs;
  private String host="localhost";
  private String user="root";
  private String pw="";
  private String db="numb1";
  private String Dri="com.mysql.jdbc.Driver";
  private String url="jdbc:mysql://"+host+"/"+db;


  public String getStr(String s){
      String str=s;
      try{
          byte b[]=str.getBytes("ISO-8859-1");
          str=new String(b);
          return str;
          }
      catch(Exception e){return null;}
  }


  public String gb2iso(String qs){ 
      try{ 
          if (qs == null) return "NULL"; 
          else return new String(qs.getBytes("gb2312"),"iso-8859-1"); 
      } 
      catch(Exception e){ 
          System.out.print("gb2iso error:"+e.getMessage()); 
      } 
      return "NULL"; 
  } 



  public void close(){//关闭连接
      try{
          if(rs!=null)rs.close();
      }catch(Exception e){
          System.out.print("rs"+e.getMessage());
      }
      try{
          if(st!=null)st.close();
      }catch(Exception e){
          System.out.print("st"+e.getMessage());
      }

      try{
          if(con!=null)con.close();
      }catch(Exception e){
          System.out.print("con"+e.getMessage());
      }
  }


  public ResultSet query(String sql)throws Exception{
      try{
          Class.forName(Dri).newInstance();
          con=DriverManager.getConnection(url,user,pw);
          st=con.createStatement();
          rs=st.executeQuery(sql);
          return rs;
      }catch(SQLException e){
         System.out.print(e.getMessage());
         return null;
      }
  }


  public void  update(String sql)throws Exception{
      try{
          Class.forName(Dri).newInstance();
          con=DriverManager.getConnection(url,user,pw);
          st=con.createStatement();
          st.executeUpdate(sql);
          st.close();
          con.close();
      }catch(SQLException e){
          System.out.print(e.getMessage());
      }
  }

}

⌨️ 快捷键说明

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