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 SQLException,ClassNotFoundException{
try
{
String url = "jdbc:mysql://localhost:3306/shopsystem";
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url,"root","ab123");
}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;
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
用jsp做的验证用户登录和注册系统小项目
共17个文件
jsp:5个
class:2个
jar:2个
5星 · 超过95%的资源 需积分: 31 243 下载量 166 浏览量
2009-11-07
22:57:55
上传
评论 4
收藏 1.31MB RAR 举报
温馨提示
用MYSQL数据库做成的,具有验证用户登录和注册这两个功能。适合初级编程人员参考,高手就要来了。
资源推荐
资源详情
资源评论
收起资源包目录
MyLogin.rar (17个子文件)
MyLogin
.settings
org.eclipse.jdt.core.prefs 334B
src
com
BaseConn.java 3KB
CheckLogin.java 2KB
.project 1KB
WebRoot
META-INF
MANIFEST.MF 39B
checkLogin.jsp 2KB
welcome.jsp 844B
WEB-INF
web.xml 375B
classes
com
CheckLogin.class 2KB
BaseConn.class 3KB
lib
mysql-connector-java-5.1.7-bin.jar 693KB
mysq链接驱动l-connector-java-5.1.8-bin.jar 707KB
register_post.jsp 2KB
login.jsp 2KB
register.jsp 2KB
.mymetadata 300B
.classpath 639B
.myeclipse
共 17 条
- 1
zwrvip
- 粉丝: 1
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页