java连接mysql数据库实现图书馆管理系统//数据库连接 MySQL:8.0.14
public class DBConnection {
public static final String DRIVER ="sql.cj.jdbc.Driver";
public static final String URL="jdbc:mysql://localhost:3306/library_management_system?serverTimezone=GMT%2B8"; //library_management_system 是⾃⼰创建的数据库名字
// public static final String URL="jdbc:mysql://localhost:3306/library_management_system";mysql5.0的
public static final String USER="root";
public static final String PASSWORD="123456";
Connection conn =null;
public DBConnection(){
try{
Class.forName(DRIVER);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
try{
conn= Connection(URL,USER,PASSWORD);
}catch(SQLException e){
e.printStackTrace();
}
}
public Connection getConnection(){
;
}
public void close(){
!=null){
try{
}catch(SQLException e){
e.printStackTrace();
}
}
}
}
管理员表
图书表
读者表
借阅表
借阅表的外键关系
javaBean
private int book_id;//图书编号
private String book_name;//书名
private String book_author;//作者
private String book_press;//出版社
public Book(int book_id, String book_name, String book_author, String book_press){ this.book_id = book_id;
this.book_name = book_name;
this.book_author = book_author;
this.book_press = book_press;
}
public int getBook_id(){
return book_id;
}
public void setBook_id(int book_id){
this.book_id = book_id;
}
public String getBook_name(){
return book_name;
}
public void setBook_name(String book_name){
this.book_name = book_name;
}
public String getBook_author(){
return book_author;
}
public void setBook_author(String book_author){
this.book_author = book_author;
}
public String getBook_press(){
return book_press;
}
public void setBook_press(String book_press){
this.book_press = book_press;
}
private int user_id;//借阅证
private String user_name;
private int user_age;
private String user_sex;
git工作流private String user_phone;
public User(int user_id, String user_name,int user_age, String user_sex, String user_phone){ this.user_id = user_id;
this.user_name = user_name;
this.user_age = user_age;
this.user_sex = user_sex;
this.user_phone = user_phone;
}
public int getUser_id(){
return user_id;
}
public void setUser_id(int user_id){
this.user_id = user_id;
}
public String getUser_name(){
return user_name;
}
public void setUser_name(String user_name){
this.user_name = user_name;
}
public int getUser_age(){
return user_age;
}
public void setUser_age(int user_age){
this.user_age = user_age;
}
public String getUser_sex(){
return user_sex;
}
public void setUser_sex(String user_sex){
this.user_sex = user_sex;
}
public String getUser_phone(){
return user_phone;
}
public void setUser_phone(String user_phone){
this.user_phone = user_phone;
}
c语言教程视频下载百度云}
private int user_id;
private int book_id;
public Borrow(int user_id,int book_id){
this.user_id = user_id;
this.book_id = book_id;
}
public int getUser_id(){
return user_id;
}
public void setUser_id(int user_id){
this.user_id = user_id;
}
public int getBook_id(){
return book_id;
}
public void setBook_id(int book_id){
this.book_id = book_id;
}
}
DBDao类
public class DBDao {
private DBConnection dbConnection = null;
private Connection conn = null;
/* private static String username;
private static String password;*/
static Scanner input =new Scanner(System.in);
public DBDao(){c语言编程一个最简单游戏代码
this.dbConnection =new DBConnection();
< = Connection();
}
mysql是什么系统//管理员登陆
public boolean denglu(){
System.out.println("----管理员登录----");
System.out.println("输⼊⽤户名:");
String ();
System.out.println("输⼊密码:");
String ();
String sql="SELECT ADMIN_NAME,ADMIN_PWD FROM ADMIN WHERE ADMIN_NAME=? AND ADMIN_PWD=?"; PreparedStatement ptmt= null;
try{
ptmt = conn.prepareStatement(sql);
ptmt.setString(1, adminName);
ptmt.setString(2, adminPwd);
ResultSet uteQuery();
()){
System.out.println("登录成功!");
return true;
}else{
System.out.println("账号或密码不正确,请重新登录!\n");
return false;
}
}catch(SQLException e){
e.printStackTrace();
return false;
}
//管理员注册
public boolean zhuce(){
System.out.println("----管理员注册----");
System.out.println("输⼊⽤户名:");
String ();
System.out.println("输⼊密码:");
String ();
简要说明servlet对象的生命周期System.out.println("再次确认密码");
String ();
if(adminPwd1.equals(adminPwd2)){
String password=adminPwd1;
String sql="INSERT INTO ADMIN(ADMIN_NAME,ADMIN_PWD) VALUES(?,?)";
PreparedStatement ptmt= null;
try{
ptmt = conn.prepareStatement(sql);
ptmt.setString(1, adminName);
ptmt.setString(2, password);
System.out.println("注册成功!");
return true;
}catch(SQLException e){
e.printStackTrace();
}
}else{
System.out.println("你输⼊的两次密码不⼀致,请重新注册!");
return false;
}
return false;
}
//新图书⼊库
public boolean insertBook(Book book){
boolean flag =false;
PreparedStatement pstmt = null;
String sql ="insert into book(book_id,book_name,book_author,book_press) values(?,?,?,?)";
try{
pstmt = conn.prepareStatement(sql);//模糊查询
pstmt.setInt(1, Book_id());
pstmt.setString(Book_name());
pstmt.setString(3, Book_author());
pstmt.setString(Book_press());
uteUpdate()>0){
flag =true;
}
}catch(SQLException e){
e.printStackTrace();
}finally{
try{
pstmt.close();
}catch(SQLException e){
e.printStackTrace();
}qevent
}
return flag;
}
//查询所有图书信息
public boolean bookInof(){
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论