0% found this document useful (0 votes)
97 views14 pages

Ip Project

The document outlines a Java library management system with classes for User, Homepage, Registration, Login, UserDetails, BookIssue, and Logout. It includes methods for signing up, logging in, retrieving and updating user details and book loans from a MySQL database. The classes work together to provide a basic functionality for users to register, login, view account details, issue and return books.

Uploaded by

Aryan Bhasein
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views14 pages

Ip Project

The document outlines a Java library management system with classes for User, Homepage, Registration, Login, UserDetails, BookIssue, and Logout. It includes methods for signing up, logging in, retrieving and updating user details and book loans from a MySQL database. The classes work together to provide a basic functionality for users to register, login, view account details, issue and return books.

Uploaded by

Aryan Bhasein
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 14

JAVA

USER CLASS:
public class User {
private String name;
private String email;
private String mobile;
private String userId;
private String password;

public String getName() {


return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
HOME PAGE:

private void SignInActionPerformed(java.awt.event.ActionEvent evt) {


Registration m=new Registration();
m.setVisible(true);
this.dispose();
}

private void LogInActionPerformed(java.awt.event.ActionEvent evt) {


Login loginFrm=new Login();
loginFrm.setVisible(true);
this.dispose();
}
REGISTRATION FORM:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.swing.*;
private void backActionPerformed(java.awt.event.ActionEvent evt) {
Home z=new Home();
z.setVisible(true);
this.dispose();
}
private void createActionPerformed(java.awt.event.ActionEvent evt) {

if(txtPassword.getText()!=null && txtPassword.getText().equals(txtConfPassword.getText())){


insertData();

}else{
//Give msg to user for password mismatch
JOptionPane.showMessageDialog(null,"Recheck the password");
}
}
private void insertData(){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=
(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/library","root","root");
Statement stmt=con.createStatement();
String qr = "Insert into user values('"+txtUserId.getText()+"','"+txtName.getText()
+"','"+txtEmail.getText()+"','"+txtMobile.getText()+"','"+txtPassword.getText()+"')";
System.out.println(qr);
int updated = stmt.executeUpdate(qr);

}catch(Exception ex){
JOptionPane.showMessageDialog(null,"Account created");
}
}
Login:

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;

private void loginActionPerformed(java.awt.event.ActionEvent evt) {


User user1 = new User();
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=
(Connection)java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/library","root","root");
Statement stmt=con.createStatement();
String query = "select user_id, user_name from user where user_id='"+txtUserId.getText()+"' and
password ='"+txtPassword.getText()+"'";
ResultSet rs=stmt.executeQuery(query);
if(rs.next()){
user1.setUserId(rs.getString("user_id"));
user1.setName(rs.getString("user_name"));
}else{
JOptionPane.showMessageDialog(null, "INVALID USERNAME");
return;
}

}catch(Exception ex){
ex.printStackTrace();
}

this.setVisible(false);
this.dispose();
UserDetails userDetails = new UserDetails();
userDetails.setVisible(true);
userDetails.user = user1;
userDetails.displayData();
}

private void backActionPerformed(java.awt.event.ActionEvent evt) {


Home p=new Home();
p.setVisible(true);
this.dispose();
}

User Details:
RETURN BOOK:

import java.sql.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
public User user;

public void displayData(){


lblUserId.setText(user.getUserId());
lblUserName.setText(user.getName());
String Chandu=lblUserId.getText();
}
private void IssueActionPerformed(java.awt.event.ActionEvent evt) {
BookIssue g =new BookIssue();
g.user2 =user;
g.displayData();
g.setVisible(true);
this.dispose();
}

private void ReturnActionPerformed(java.awt.event.ActionEvent evt) {


String Chandu=lblUserId.getText();
try{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=(Connection)java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/library","root","ro
ot");
Statement stmt=con.createStatement();
String m="Update book_issue set submitted='Y' where user_id='"+Chandu+"'";

stmt.executeUpdate(m);
}catch (Exception e ){
System.out.println(e.getMessage());
}JOptionPane.showMessageDialog(null,"BOOK SUBMITTED");
}

private void ShowActionPerformed(java.awt.event.ActionEvent evt) {


try{
DefaultTableModel model = (DefaultTableModel)tblBookIssue.getModel();
for( int i = model.getRowCount() - 1; i >= 0; i-- ) {
model.removeRow(i);
}
Class.forName("com.mysql.jdbc.Driver");
Connection
con=(Connection)java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/library","root","ro
ot");
Statement stmt=con.createStatement();
String a = "Select * from book_issue where user_id='"+lblUserId.getText()+"';";
ResultSet rs=stmt.executeQuery(a);
while (rs.next())
{
String bookname=rs.getString("book_name");
String submitted=rs.getString("submitted");
model.addRow(new Object[]{bookname,submitted});
}
}catch (Exception e ){
System.out.println(e.getMessage());
}
}

Book Issue:
Issue:

Logout:
import javax.swing.*;
import java.sql.*;

String qr="";
lt = new DefaultListModel();
BookList.setModel(lt);
int c= Bookscb.getSelectedIndex();
try{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=(Connection)java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/library","root","ro
ot");
Statement stmt=con.createStatement();
if (c==0)
qr="Select book_name from book where book_type='fiction'";
else if (c==1)
qr="Select book_name from book where book_type='non-fiction'";
else if (c==2)
qr="Select book_name from book where book_type='fantasy'";
else if (c==3)
qr="Select book_name from book where book_type='thriller'";
ResultSet rs=stmt.executeQuery(qr);
String s="";
while (rs.next())
{
s=rs.getString("book_name");
lt.addElement(""+s);
}
rs.close();
stmt.close();
con.close();
System.out.println("Close");
}catch(Exception e)
{
System.out.print(e.getMessage());
}
}

private void issueActionPerformed(java.awt.event.ActionEvent evt) {


String a= BookList.getSelectedValue();
try{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=(Connection)java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/library","root","ro
ot");
Statement stmt=con.createStatement();
String qr="Insert into book_issue values('"+a+"','"+lblUserId.getText()+"','N');";
//stmt.executeQuery(qr);
stmt.executeUpdate(qr);
}catch (Exception e)
{
System.out.print(e.getMessage());
}
JOptionPane.showMessageDialog(null, "BOOK ISSUED");
}

private void backActionPerformed(java.awt.event.ActionEvent evt) {


this.dispose();
UserDetails userDetails = new UserDetails();
userDetails.user=user2;
userDetails.displayData();
userDetails.setVisible(true);
}

private void logoutActionPerformed(java.awt.event.ActionEvent evt) {


JOptionPane.showMessageDialog(null,"THANK YOU,PLEASE VISIT US AGAIN");
this.dispose();
this.setVisible(false);
Home home =new Home();
home.setVisible(true);
}

Mysql Queries:

You might also like