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

📄 database.java

📁 很实用的JSP代码
💻 JAVA
字号:
package bookshop.util;
/**
 * <p>数据库连接专用包 </p>
 * <p>Copyright: wxy Copyright (c) 2004</p>
 * <p>Company:juanjuan book shop online </p>
 * @by :wxy
 * @version 1.0
 */
import java.sql.*;
public class DataBase {
  public Connection conn;
  public Statement stmt;
  public ResultSet rs=null;
  public String sqlStr="";
  public String m_strErrMsg = "";

  public DataBase() {
    this.connect();
  }
  public void finalize()
  {
     try
     {
       if (rs != null) {
         rs.close(); ;
       }
       if( stmt != null )
       {
         stmt.close();
       }
       if( conn != null)
       {
          conn.close();
       }

     }
     catch(Exception ex)
     {
       System.out.println("connect db error:"+ex.getMessage());
     }
  }

 public boolean connect(){
      try{
        Class.forName("org.gjt.mm.mysql.Driver").newInstance();
        String url ="jdbc:mysql://localhost/BookStore?user=root&password=19850103&characterEncoding=GB2312";
        conn=DriverManager.getConnection(url);
        stmt = conn.createStatement ();
       }catch(Exception ee){
         m_strErrMsg = "使用JDBC驱动连接数据库错误:" + ee.getMessage();
         System.out.println("connect db error:"+ee.getMessage());
        return false;
       }
      return true;
    }
 public static void main(String[] args) {
     try{
            DataBase db = new DataBase();
            db.connect();
          }catch(Exception e){
            e.printStackTrace();
          }
        }
}

⌨️ 快捷键说明

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