package fjzzy.org;
import java.sql.*;
public class ConnDB {
int i=0;
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
static String url="jdbc:mysql://localhost:3306/work";
static String user="root";
static String password="123456";
//连接数据库的方法
public static Connection getConnection(){
Connection conn=null;
try {
Class.forName("com.mysql.jdbc.Driver");//注册驱动类
}catch(ClassNotFoundException e){//没有找到驱动类时
System.out.print("无法找到驱动类");
}
try {
conn=DriverManager.getConnection(url, user, password);
} catch (SQLException e) {
e.printStackTrace();
}
if(conn==null){
System.out.print("数据库连接失败");
}
return conn;
}
//用户名登陆
public ResultSet doQuery(String sql,String name,String password){
try{
conn=ConnDB.getConnection();
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setString(2, password);
rs=pstmt.executeQuery();
}catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
//手机号登陆
public ResultSet doQuery2(String sql,String name,String telphone){
try{
conn=ConnDB.getConnection();
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setString(2, telphone);
rs=pstmt.executeQuery();
}catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
//注册
public int doUpdate(String sql,String name,String password,String telphone){
try{
conn=ConnDB.getConnection();
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setString(2, password);
pstmt.setString(3, telphone);
i=pstmt.executeUpdate();
}catch (SQLException e) {
e.printStackTrace();
}
return i;
}
//用户名验证
public ResultSet checkname(String sql,String name){
try{
conn=ConnDB.getConnection();
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, name);
rs=pstmt.executeQuery();
}catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
//手机号验证
public ResultSet checktelphone(String sql,String telphone){
try{
conn=ConnDB.getConnection();
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, telphone);
rs=pstmt.executeQuery();
}catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
//数据库模糊查询
public ResultSet selectsql(String sql,String bookname){
try {
conn=ConnDB.getConnection();
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, "%" + bookname + "%");
rs=pstmt.executeQuery();
} catch (Exception e) {
// TODO: handle exception
}
return rs;
}
//书籍录入
public int insert(String sql,String bookid, String bookname,String booktype,String bookwriter,String bookdetail,String bookprice,String bookstock,String bookimgsrc){
try{
conn=ConnDB.getConnection();
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, bookid);
pstmt.setString(2, bookname);
pstmt.setString(3, booktype);
pstmt.setString(4, bookwriter);
pstmt.setString(5, bookdetail);
pstmt.setString(6, bookprice);
pstmt.setString(7, bookstock);
pstmt.setString(8, bookimgsrc);
i=pstmt.executeUpdate();
}catch (SQLException e) {
e.printStackTrace();
}
return i;
}
//书籍修改
public int updata(String sql,String bookid, String bookname,String booktype,String bookwriter,String bookdetail,String bookprice,String bookstock,String bookimgsrc){
try{
conn=ConnDB.getConnection();
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, booktype);
pstmt.setString(2, bookwriter);
pstmt.setString(3, bookdetail);
pstmt.setString(4, bookprice);
pstmt.setString(5, bookstock);
pstmt.setString(6, bookimgsrc);
pstmt.setString(7, bookname);
pstmt.setString(8, bookid);
i=pstmt.executeUpdate();
}catch (SQLException e) {
e.printStackTrace();
}
return i;
}
//删除书籍
public int delete(String sql,String bookid, String bookname,String booktype){
try{
conn=ConnDB.getConnection();
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, bookid);
pstmt.setString(2, bookname);
pstmt.setString(3, booktype);
i=pstmt.executeUpdate();
}catch (SQLException e) {
e.printStackTrace();
}
return i;
}
//查找类型
public ResultSet selecttype(String sql){
try {
conn=ConnDB.getConnection();
pstmt=conn.prepareStatement(sql);
rs=pstmt.executeQuery();
} catch (Exception e) {
// TODO: handle exception
}
return rs;
}
//删除用户
public int delectuser(String sql,String name){
try{
conn=ConnDB.getConnection();
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, name);
i=pstmt.executeUpdate();
}catch (SQLException e) {
e.printStackTrace();
}
return i;
}
//book删除库存
public int updatebook(String sql,int bookstock, String bookid){
try{
conn=ConnDB.getConnection();
pstmt=conn.prepareStatement(sql);
pstmt.setInt(1,bookstock);
pstmt.setString(2, bookid);
i=pstmt.executeUpdate();
}catch (SQLException e) {
e.printStackTrace();
}
return i;
}
//book删除lingshi
public int deletelingshi(String sql, String name){
try{
conn=ConnDB.getConnection();
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,name);
i=pstmt.executeUpdate();
}catch (SQLException e) {
e.printStackTrace();
}
return i;
}
//借阅管理
public ResultSet selectbook(String sql,String bookid){
try {
conn=ConnDB.getConnection();
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, bookid);
rs=pstmt.executeQuery();
} catch (Exception e) {
// TODO: handle exception
}
return rs;
}
public ResultSet selectuser(String sql,String name){
try {
conn=ConnDB.getConnection();
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, name);
rs=pstmt.executeQuery();
} catch (Exception e) {
// TODO: handle exception
}
return rs;
}
public int insertborrow(String sql,String bookid,String bookname,String booktype,int booknumber,String bookdate,String bookrule_date,String name){
try{
conn=ConnDB.getConnection();
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, bookid);
pstmt.setString(2, bookname);
pstmt.setString(3, booktype);
pstmt.setInt(4, booknumber);
pstmt.setString(5, bookdate);
pstmt.setString(6, bookrule_date);
pstmt.setString(7, name);
i=pstmt.executeUpdate();
}catch (SQLException e) {
e.printStackTrace();
}
return i;
}
//加入临时表
public int lingshi(String sql,String bookid,String name,String bookname){
try{
conn=ConnDB.getConnection();
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, bookid);
pstmt.setString(2, name);
pstmt.setString(3, "1");
pstmt.setString(4, bookname);
i=pstmt.executeUpdate();
}catch (SQLException e) {
e.printStackTrace();
}
return i;
}
public ResultSet id(String sql,String name){
try{
conn=ConnDB.getConnection();
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, name);
rs=pstmt.executeQuery();
}catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
public ResultSet id(String sql){
try{
conn=ConnDB.getConnection();
pstmt=conn.prepareStatement(sql);
rs=pstmt.executeQuery();
}catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
//删除lingshi表
public int delete3(String sql,String id,String n
没有合适的资源?快使用搜索试试~ 我知道了~
JSP期末项目(图书馆管理系统附数据库)
共170个文件
png:98个
jsp:21个
class:14个
5星 · 超过95%的资源 需积分: 20 94 下载量 100 浏览量
2018-02-08
20:35:00
上传
评论 17
收藏 12.95MB ZIP 举报
温馨提示
适用初学者 大二jsp期末项目 1、建立正确的javabean类 2、编写javabean属性和方法 3、用到jdbc驱动程序连接数据 4、对数据库增删改查 5、使用PreparedStetement接口
资源推荐
资源详情
资源评论
收起资源包目录
JSP期末项目(图书馆管理系统附数据库) (170个子文件)
ConnDB.class 9KB
BorrowServlet2.class 4KB
ChangeServlet.class 4KB
BorrowServlet.class 4KB
DeleteBookServlet2.class 3KB
DetailServlet.class 3KB
AddServlet.class 3KB
ChangeServlet2.class 3KB
DeleteGouwucheServlet.class 3KB
DeleteServlet.class 2KB
DeleteJieYueChe.class 2KB
DeleteBookServlet.class 2KB
DelectuserServlet.class 2KB
Bookid.class 449B
.classpath 944B
org.eclipse.wst.common.component 464B
org.eclipse.wst.jsdt.ui.superType.container 49B
index.html 8KB
Login.html 3KB
SouSuo.html 3KB
reg.html 2KB
YouSheng.html 2KB
ShiShi.html 2KB
ZhuanYe.html 2KB
WenXue.html 2KB
find_ok.html 441B
reg_ok.html 439B
ConnDB.java 10KB
BorrowServlet2.java 4KB
BorrowServlet.java 4KB
ChangeServlet.java 4KB
DetailServlet.java 3KB
ChangeServlet2.java 3KB
AddServlet.java 3KB
DeleteBookServlet2.java 3KB
DeleteGouwucheServlet.java 2KB
DeleteServlet.java 2KB
DeleteJieYueChe.java 2KB
DeleteBookServlet.java 2KB
DelectuserServlet.java 2KB
Bookid.java 216B
书背景.jpg 1.23MB
密码图标.jpg 12KB
用户图标.jpg 12KB
.jsdtscope 567B
index.jsp 12KB
ShiShi.jsp 6KB
ZhuanYe.jsp 6KB
YouSheng.jsp 6KB
WenXue.jsp 6KB
SouSuo_ok.jsp 6KB
Admin4.jsp 6KB
Admin2.jsp 5KB
XiuGai.jsp 5KB
Admin5.jsp 5KB
Admin1.jsp 5KB
Admin3.jsp 4KB
SouSuo.jsp 3KB
find.jsp 3KB
bookdetail.jsp 3KB
JieYueChe.jsp 3KB
Admin.jsp 3KB
Login_ok.jsp 2KB
reg_ok.jsp 2KB
find_ok.jsp 1KB
Tuichu.jsp 486B
MANIFEST.MF 39B
org.eclipse.wst.jsdt.ui.superType.name 6B
书.png 5.85MB
后尾.png 5.75MB
书背景.png 4.92MB
reg.png 2.48MB
Login1.png 2.48MB
Login.png 2.48MB
reg_ok.png 2.48MB
reg1.png 2.48MB
背景.png 2.06MB
背景2.png 1.65MB
左侧栏-bottom.png 655KB
top22.png 440KB
Login-top.png 425KB
reg-top.png 425KB
modify_ok.png 425KB
index-top1.png 344KB
top3.png 340KB
top33.png 271KB
top2.png 256KB
top.png 256KB
choose1.png 158KB
加载中.png 84KB
长江日报.png 84KB
人民日报.png 84KB
中国周刊.png 84KB
财经.png 84KB
环球人物.png 84KB
凤凰周刊.png 84KB
闽南日报.png 84KB
TIME.png 84KB
新周刊.png 84KB
新华日报.png 84KB
共 170 条
- 1
- 2
资源评论
- weixin_438756892019-06-25用起来很不错迷茫的21世纪的新轻年2019-06-29谢谢
- weixin_451538332019-06-04感觉很棒,就是我很笨,还没研究透彻迷茫的21世纪的新轻年2019-06-07哈哈,加油啊
迷茫的21世纪的新轻年
- 粉丝: 723
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功