• 大小: 672KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-10
  • 语言: Java
  • 标签: jsp  MySQL  登录  注册  

资源简介

这是一个用jsp语言写的一个用户注册和登录系统,数据库用的是MySQL,连接方式封装到类里面。

资源截图

代码片段和文件信息

package com;
import java.sql.*;
import java.lang.ClassNotFoundException;
public class baseConn {
private Connection conn = null;
private Statement stmt = null;
private PreparedStatement ps = null;
private ResultSet rs = null;
public baseConn() throws SQLExceptionClassNotFoundException{
try
{
String url = “jdbc:mysql://localhost:3306/mytest“;
Class.forName(“com.mysql.jdbc.Driver“);
conn = DriverManager.getConnection(url“root““6121485“);
}catch(SQLException e)
{
System.out.println(“Error occured when Connect Database:“+e);
throw e;
}
catch(ClassNotFoundException e)
{
System.out.println(“Error occured when Connect Database:“+e);
throw e;
}
}
public PreparedStatement preparedStatement(String sql) throws SQLException
{
try
{
ps = conn.prepareStatement(sql);
return ps;
}catch(SQLException e)
{
System.out.println(“Error occured when Connect Database:“+e);
throw e;
}
}
/**
   * 执行静态 SQL 查询语句并返回它所生成结果的对象
   * */
  public ResultSet executeQuery(String sql) throws SQLException
  {
    rs = null;
    try {
      rs = stmt.executeQuery(sql);
    }
    catch (SQLException ex) {
      System.out.println(“Error occured when query database:“ + ex);
      throw ex;
    }
    return rs;
  }
  
  /**
   * 执行静态SQL更新语句并返回影响数据条数
   * */
  public int executeUpdate(String sql) throws SQLException
  {
    try {
      conn.setAutoCommit(false);
      int re = stmt.executeUpdate(sql);
      conn.commit();
      return re;
    }
    catch (SQLException e) {
      conn.rollback();
      System.out.println(“Error occured when update database:“ + e);
      throw e;
    }
  }  
  /**
   * 执行预编译的SQL查询语句
   * 
   * */
  public ResultSet executeQuery() throws SQLException
  {
    try {
      return ps.executeQuery();
    }
    catch (SQLException e) {
      System.out.println(“Error occured when query database:“ + e);
      throw e;
    }
  }
  /**
   * 执行预编译的SQL更新语句
   * 
   * */
  public int executeUpdate() throws SQLException
  {
    try {
      conn.setAutoCommit(false);
      int r = ps.executeUpdate();
      conn.commit();
      return r;
    }
    catch (SQLException e) {
      conn.rollback();
      System.out.println(“Error occured when update database:“ + e);
      throw e;
    }
  }
 /**
  * 数据库关闭操作
  * */
  public boolean closeDB() throws SQLException
  {
    try {
      if (this.rs != null)
        rs.close();
      if (this.stmt != null)
        this.stmt.close();
      if (this.ps != null)
        this.ps.close();
      if (this.conn != null)
        conn.close();
      return true;
    }
    catch (SQLException e) {
      System.out.println(“Error occured when close database:“ + e);
      throw e;
    }
  }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        542  2009-07-13 09:05  testMySQL\.classpath

     文件        300  2009-07-11 11:26  testMySQL\.mymetadata

     文件       1227  2009-07-11 12:37  testMySQL\.project

     文件        334  2009-07-11 11:26  testMySQL\.settings\org.eclipse.jdt.core.prefs

     文件       2990  2009-07-12 15:40  testMySQL\src\com\baseConn.java

     文件       2520  2009-07-13 10:27  testMySQL\src\com\CheckLogin.java

     文件       1848  2009-07-12 15:11  testMySQL\WebRoot\checkLogin.jsp

     文件       1967  2009-07-12 14:57  testMySQL\WebRoot\login.jsp

     文件         39  2009-07-11 11:26  testMySQL\WebRoot\meta-INF\MANIFEST.MF

     文件       2026  2009-07-13 10:35  testMySQL\WebRoot\register.jsp

     文件       2162  2009-07-13 10:54  testMySQL\WebRoot\register_post.jsp

     文件       3162  2009-07-13 09:05  testMySQL\WebRoot\WEB-INF\classes\com\baseConn.class

     文件       2118  2009-07-13 10:27  testMySQL\WebRoot\WEB-INF\classes\com\CheckLogin.class

     文件     709922  2008-05-12 19:14  testMySQL\WebRoot\WEB-INF\lib\mysql-connector-java-5.1.7-bin.jar

     文件        375  2009-07-12 14:35  testMySQL\WebRoot\WEB-INF\web.xml

     文件        844  2009-07-12 14:55  testMySQL\WebRoot\welcome.jsp

     目录          0  2009-07-13 10:58  testMySQL\WebRoot\WEB-INF\classes\com

     目录          0  2009-07-13 10:58  testMySQL\WebRoot\WEB-INF\classes

     目录          0  2009-07-13 10:58  testMySQL\WebRoot\WEB-INF\lib

     目录          0  2009-07-13 10:58  testMySQL\src\com

     目录          0  2009-07-13 10:58  testMySQL\WebRoot\meta-INF

     目录          0  2009-07-13 10:58  testMySQL\WebRoot\WEB-INF

     目录          0  2009-07-13 10:58  testMySQL\.myeclipse

     目录          0  2009-07-13 10:58  testMySQL\.settings

     目录          0  2009-07-13 10:58  testMySQL\src

     目录          0  2009-07-13 10:58  testMySQL\WebRoot

     目录          0  2009-07-13 10:58  testMySQL

----------- ---------  ---------- -----  ----

               732376                    27



............此处省略0个文件信息

评论

共有 条评论