package dao;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.*;
import javax.swing.JOptionPane;
import javabean.AtBean;
import javabean.BookBean;
import javabean.BuyBean;
import javabean.JournalBean;
import javabean.UserBean;
public class DataBase {
String url = "jdbc:mysql://localhost:3306/blogbokeinfo?useUnicode=true&characterEncoding=utf-8";
String user = "root";
String password = "root";
Connection con = null;
Statement st = null;
ResultSet rs = null;
String diverName = "com.mysql.jdbc.Driver";
// 建立数据库链接,返回数据库操作对象
public Statement getSt() {
try {
Class.forName(diverName);
con = DriverManager.getConnection(url, user, password);
return con.createStatement();
} catch (Exception e) {
e.printStackTrace();
message("数据库链接错误,请检查getst()方法");
return null;
}
}
private void message(String msg) {
int type = JOptionPane.YES_NO_CANCEL_OPTION;// 消息框类别
String title = "消息提示";
JOptionPane.showConfirmDialog(null, msg, title, type);
}
private void wrong() {
String msg = "注册失败,用户名已经存在!";
int type = JOptionPane.YES_NO_OPTION;// 消息框类别
String title = "消息提示";
JOptionPane.showConfirmDialog(null, msg, title, type);
}
private void right() {
String msg = "注册成功!";
int type = JOptionPane.YES_NO_OPTION;// 消息框类别
String title = "消息提示";
JOptionPane.showConfirmDialog(null, msg, title, type);
}
// 登录验证
public boolean isLogin(String userName, String password2) {
// 验证登录
try {
String sql = "select * from userInfo where userName='" + userName + "'and password='" + password2 + "'";
st = getSt();
rs = st.executeQuery(sql);
// 判断结果集是否有数据。代表是否登录成功
if (rs.next()) {
return true;
} else {
return false;
}
} catch (Exception e) {
e.printStackTrace();
message("登录验证错误,请检测isLogin()方法");
return false;
}
}
// 检查用户重名方法 -->为了注册
public int getUserCount(String userName) {
try {
String sql = "select * from userInfo where userName='" + userName + "'";
st = getSt();
rs = st.executeQuery(sql);
int a = 0;
while (rs.next()) {
a = 1;
}
return a;
} catch (Exception e) {
e.printStackTrace();
message("查询用户错误,请检测getUserCount()方法");
return 2;
}
}
// 注册用户名和密码数据
public void insertUser(String userName, String password2) {
try {
String sql = "insert into userInfo(userName,password) values('" + userName + "','" + password2 + "')";
st = getSt();
st.executeUpdate(sql);
st.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
message("注册用户错误,请检测insertUser()方法");
}
}
// 留言板数据添加
public void insertMsg(String content, String author, String addtime) throws SQLException {
int id = 0;
String sql = "insert into msginfo(id,msgCt,addtime,msgUser) values('" + id + "','"
+ content + "','" + addtime + "','" + author + "',)";
Statement st = con.createStatement();
st.executeUpdate(sql);
st.close();
con.close();
}
// 统计留言条数
public long msgNumbers() {
try {
st = getSt();
String sql = "select * from msginfo";
ResultSet rs = st.executeQuery(sql);
rs.last();
int msgbds = rs.getRow();
rs.first();
st.close();
con.close();
return msgbds;
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
// 查找留言所有数据
public ResultSet selectMsgbd() {
try {
String sql = "select * from msginfo";
st = getSt();
rs = st.executeQuery(sql);
return rs;
} catch (Exception e) {
e.printStackTrace();
message("查询留言信息错误,请检测selectMsgbd()方法");
return null;
}
}
// 添加留言方法
public boolean addMsgbd(String content, String author, String addtime) {
try {
int id = 0;
String sql = "insert into msginfo(id,msgCt,addtime,msgUser) values('"+id+"','"+content+"','"+addtime+"','"+author+"')";
st = getSt();
int row = st.executeUpdate(sql);
st.close();
con.close();
if (row == 1) {
return true;
} else {
return false;
}
} catch (Exception e) {
e.printStackTrace();
message("增加留言信息错误,请检测addMsgbd()方法");
return false;
}
}
//文章上传
public void uploadAtricle(String atTitle, String atContent, String atSort, String atLabel, String addtime,
String author, File img, String atMin,String imgUrl) {
try {
//利用文件输入流,将图片转换为字节存放到数据库中
FileInputStream fis = new FileInputStream(img);
// 编写sql语句
String sql = "insert into articleInfo(atTitle,atContent,atSort,atLabel,addtime,author,upLoadFile,atMin,imgUrl) values('"+atTitle+"','"+atContent+"','"+atSort+"','"+atLabel+"','"+addtime+"','"+author+"','"+fis+"','"+atMin+"','"+imgUrl+"')";
System.out.println("执行了sql");
st = getSt();
st.executeUpdate(sql);
// 预编译处理sql语句
// 读取图片
fis.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("上传文章成功");
}
// 用户总数统计
public int selectCountUb() {
try {
String sql = "select * from userinfo";
st = getSt();
rs = st.executeQuery(sql);
rs.last();
int intRowCount=rs.getRow();
rs.close();
return intRowCount;
} catch (Exception e) {
e.printStackTrace();
message("用户总数信息错误,请检测selectCountAt()方法");
return 0;
}
}
// 用户分页
public ResultSet selectUbCondition(int _start, int _rows) {
try {
int start=(int)_start;
int rows=(int)_rows;
String sql = "select * from userinfo limit"+" "+start+","+rows;
System.out.println(start);
System.out.println(start);
System.out.println(sql);
st=getSt();
rs = st.executeQuery(sql);
return rs;
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
message("用户分页查询信息错误,请检测selectUbCondition()方法");
return null;
}
}
//文章总数统计
public int selectCountAt() {
try {
String sql = "select * from articleInfo";
st = getSt();
rs = st.executeQuery(sql);
rs.last();
int intRowCount=rs.getRow();
rs.close();
return intRowCount;
} catch (Exception e) {
e.printStackTrace();
message("查询文章总数信息错误,请检测selectCountAt()方法");
return 0;
}
}
//文章分页查询
public ResultSet selectAtCondition(int _start, int _rows) {
try {
int start=(int)_start;
int rows=(int)_rows;
String sql = "select * from articleInfo limit"+" "+start+","+rows;
System.out.println(start);
System.out.println(start);
System.out.println(sql);
st=getSt();
rs = st.executeQuery(sql);
return rs;
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
message("文章分页查询信息错误,请检测selectAtCondition()方法");
return null;
}
}
//添加说说
public void addJournal(String atContent, String author, String addtime) {
try {
String sql = "insert into journalinfo(atContent,author,addtime) values('"+atContent+"','"+author+"','"+addtime+"')";
st = getSt();
st.executeUpdate(sq
没有合适的资源?快使用搜索试试~ 我知道了~
博客文章说说留言书城(文章图片上传)+数据分页基于JavaWeb项目(纯jsp+servlet+jdbc)+登录注册
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共183个文件
java:37个
class:37个
jpg:32个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 63 浏览量
2023-12-02
15:53:45
上传
评论
收藏 16.13MB ZIP 举报
温馨提示
登录注册,非法访问验证,博客的用户文章发布,心情说说,日志的增删改查,访客用户的管理,博客运行时间统计,博客书城的管理,图书的上架售卖以及结算(结算的功能还没写),纯手写前台页面,大概20左右个CSS,每个基本400-500行代码,DAO层稍稍有点乱,都写在了一个文件里面,是之前的课程设计想着分享给大家。
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JAR.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JAR.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JAR.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JAR.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JAR.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 183 条
- 1
- 2
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
![avatar-vip](https://csdnimg.cn/release/downloadcmsfe/public/img/user-vip.1c89f3c5.png)
手把手教你学AI
- 粉丝: 8811
- 资源: 4771
![benefits](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-1.c8e153b4.png)
下载权益
![privilege](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-2.ec46750a.png)
C知道特权
![article](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-3.fc5e5fb6.png)
VIP文章
![course-privilege](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-4.320a6894.png)
课程特权
![rights](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-icon.fe0226a8.png)
开通VIP
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)