5/17 - Hotel Management System | Java Project | Creating Connection with the database
Vložit
- čas přidán 5. 04. 2022
- In this video we will create our connection with the MySQL Database using a concept called JDBC. VERY IMPORTANT FOR INTERVIEW
Please find the playlist of Complete Hotel Management System Java Project
• 1/17 - Hotel Managemen...
Technologies Used: Core Java (Swing & AWT)
Database Used: MySQL
IDE used: Netbeans
---------------------------------------------------------------------------------------------
Please find the source code of the Project
github.com/kunaltyagi9/Hotel-...
Please find the Google Drive link for icons and database file
drive.google.com/drive/folder...
Please find Google Drive link for Project File
drive.google.com/drive/folder...
---------------------------------------------------------------------------------------------
Please contribute the documentation of this Project to help others
How to Download Java, watch this video
• Install Java JDK 17 on...
How to Download Netbeans, watch this video
• How to Download and In...
How to Download MySQL, do watch this video
• How to Install MySQL o...
Java Projects Playlist: • 1/12 - Bank Management...
JavaScript Projects Playlist: • JavaScript Projects
React Projects Playlist: • React Projects
MERN Stack Projects Playlist: • MERN Stack Projects
Follow Us
Instagram: codeforinterview ( / codeforinterview )
Telegram: codeforinterview (t.me/codeforinterview)
Please find below the playlist of Hotel Management System
czcams.com/video/E7m5ci3dsKo/video.html
Watch the next video to create the AddEmployee class
czcams.com/video/zpilHuidl3k/video.html
Very detailed explanation thank you so much
7:18 i have never used sql workbench how did you open the file tab where you wrote create data base please help
press ctrl + n
or check the header tab options for the new file
Hello its giving me and error on unknown column 'password' in where clause
i have checked every line of code still couldn't able to fix it
I am waiting for you sir😊
😂
I have already added jar file still error during login again and again plz sir help i have to submit this project for my final year
7:36 can't create databse hotelmanagementsystem , error shown. How do i handle??
What is the meaning of( this ) in action listener...what if the interviewer asks me what should I say
the code you are writing in the video, and the code in github which u provided is different
It's showing the same error after logging... invalid userid and password.. How to solve this issue
that was super helpful! do you by any chanse have english translate? or videos in english?
I am sorry, I have not
💥💥💥💥💥
i am facing this error: Cannot invoke "javax.swing.JTextField.getText()" because "this.password" is null
what should i do ?
this error is in my password
make sure you have removed the local declaration of JTextField after declaring it as global variable
Bro while after login it’s not opening dashboard it’s showing error cannaot invoke sql.statement.execute query of string because c.s is null
Go to conn class, in the catch section, write this
e.printStackTrace();
run the application again and this time another expection will print on console
reply with that exception
@@codeforinterviewc.s is null same yhi error dera tb bhi
@@diptipundir3728 i think you have declared it 2 times (JTextField and JButton) remove it from username and in the code.
@@malavshah6244 thanku abhi chlgya sb shi se or humara project complete bhi hogya 😊
What is the type of architecture in this?
Sir I'm using vs code for this project I can't understand why there is some glitch when the code runs like menu and menu item takes some time to get visible
Do you have setVisible at the end of the constructor?
Sir login button not working properly
When I click login button i proper fill username and password then says invalid username and password why? But cancel button work properly
Sir no any solution sir
@@ankitray4873
check for currently using database
check for field names in database also check field names in project,
JTextField userName;
JPasswordField password;
userName = new JTextField();
password = new JPasswordField()
String user = userName.getText();
String pass = password.getText();
String query = "SELECT * FROM login WHERE username = '" + user + "' AND password = '" + pass + "'";
where my table is
create table login(username varchar(25), password varchar(25));
I'm unable to add jar files. Does anyone know?
I'm using VS Code IDE and facing some problem during connecting with the database Jar file isn't opening in my PC tell me where I should locate my Jar file.. I created a folder called Libraies and pasted the jar file in that browser..
I am sorry, I never ran java in vs code. So, I have no clue
ik its late but for newcommers
on the left of the VS code IDE in u have EXPLORER section im not that fammiliar with terminology so ill explain it as simple as i can
so on the top u have "basic folder structure for a project" ex "hotelmanagementsystem" and folders inside (i think IDE sees it as just folder structure not a project structure)
and thers also
OUTLINE
TIMELINE
AND THERE SHOULD BE "JAVA PROJECTS" (thats probaly what IDE sees as a java project)
there should be something called "Refferenced Libraries" u just simply click + button and looking for a file in a windows file explorer
same problem in vs code please tell me about this problem...@@SUB-np7uk
Hello sir
Having this problem.. kindly help to resolve. The login button gives this error
java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= 'admin' and password = '12345'' at line 1
Same error
Have your error resolved and how?
Not action is performed when clicking cancel so what can i do plss reply sir
check if you have actionlistener on the cancel button
Sir can you pls tell me how can I connect xampp database in this java project bcz my MySQL is not working
the procedure to create database is still the same
@@codeforinterview okay it's done thank uh for ur help
@@varshashrestha84 can u help me with the same
Hey sir Agr hm hotel management system main jar file lagatay hein phir project bilkul mast chalta ha or zip file main kar ky kisi dusray laptop main run krain gay tw kia wo jo jar file dubara lagani hogi yah khud wo lagi hogi phelay sae ?
jar file kaha se milegi yaar....
I want to blinking text (The tan group welcomes you)in dashboard class but if I login using login class then It shows blank frame in dashboard class no image no text please help me to adjust this
You can move ahead without this, because you will not come back to the Splash screen after the Login screen
@@codeforinterview why what's the reason???
And if I apply image slides on dashboard if I login using login class then also so blank on the dashboard class frame
Sir reply please
Sir i am getting error in login class when i extends Jframe amd implement action listener
Error showing on screen is- login is not abstract and does not override abstract method actionperformed
Please help
make sure you have the below method in the class with the exact syntax and case.
public void actionPerformed(ActionEvent ae){}
The spelling with correct casing is actionPerformed, make sure you are writing the same
public void actionPerformed(ActionEvent ae){}
Sir i am putting right username and password then also it is showing invalid
Sir data base can't create in MySQL what we do
What is the error you have?
Sir , when I click login button then it show invalid username and password while I proper fill username and password then it says invalid username and password why? While cancel button works properly sir tell me immediatry sir i am waiting to your response sir
Do you have any space in the mysql table after username and password?
@@codeforinterview yes sir
@@AnkitKumar-xj5jz
check for currently using database
check for field names in database also check field names in project,
JTextField userName;
JPasswordField password;
userName = new JTextField();
password = new JPasswordField();
String user = userName.getText();
String pass = password.getText();
String query = "SELECT * FROM login WHERE username = '" + user + "' AND password = '" + pass + "'";
where my table is
create table login(username varchar(25), password varchar(25));
I'm getting this error Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO)
looks like ur not passing password as an argument for connecting to db but im not sure
Sir in class actionperformed class
In string pass = password. getText (in getText strikethrough symbool ) is found why?
It is just a deprecation warning, ignore that
or you can change this function to getPassword
@@codeforinterview sir if I changed
String pass = password. getpassword() then getpassword get error why?
@@ankitray4873 getPassword(), with P uppercase
@@codeforinterview sir whole line get error
@@ankitray4873 you must have got the typecast error, typecast it in a string. It will work
new String(passsword.getPassword());
hello sir my login code is not working and i am not able to get the ans could you please help me.
Do you have any error on console?
did you changed the code which u have uploaded on github??
i have connected the database but the problem i am facing is that it is unable to check the username and pass from the mysql, despite of entering right username and password , it is showing me invalid password and username
please check the mysql query you are executing
@@codeforinterview thanks for replying,
i dropped the database and made a new one , now its working fine ..( I don't know how it worked 😂)
@@AbdulRehman-er2lw 😂😂
I am getting the same error even after entering correct username and password
package hotel.management.system;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Login extends JFrame implements ActionListener {
JTextField username,password;
JButton login,cancel;
Login(){
getContentPane().setBackground(Color.LIGHT_GRAY);
setLayout(null);
JLabel user= new JLabel("Username");
user.setFont(new Font("self",Font.PLAIN,16));
user.setBounds(40,20,100,30);
add(user);
username=new JTextField();
username.setBounds(150,20,200,30);
add(username);
JLabel pass=new JLabel("Password");
pass.setFont(new Font("self",Font.PLAIN,16));
pass.setBounds(40,70,100,30);
add(pass);
password=new JTextField();
password.setBounds(150,70,200,30);
add(password);
login=new JButton("Login");
login.setFont(new Font("self",Font.PLAIN,16));
login.setBackground(Color.WHITE);
login.setForeground(Color.BLACK);
login.setBounds(40,150,100,30);
login.addActionListener(this);
add(login);
cancel=new JButton("Cancel");
cancel.setFont(new Font("self",Font.PLAIN,16));
cancel.setBackground(Color.WHITE);
cancel.setForeground(Color.BLACK);
cancel.setBounds(200,150,100,30);
cancel.addActionListener(this);
add(cancel);
//ImageIcon i1=new ImageIcon(ClassLoader.getSystemResource("/icons/second.jpg"));
// JLabel image=new JLabel(i1);
java.net.URL i1=getClass().getResource("/icons/second.jpg");
Icon see=new ImageIcon(i1);
//Image i2= i1.getImage().getScaledInstance(200,200,Image.SCALE_DEFAULT);
// ImageIcon i3=new ImageIcon(i2);
JLabel image=new JLabel(see);
image.setBounds(400,40,160,160);
add(image);
setBounds(500,200,600,300);
setVisible(true);
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==login){
String user=username.getText();
String pass=password.getText();
try{
conn c =new conn();
String query="select * from login where username - '" + user + "' and password - '" + pass + "'";
ResultSet rs= c.s.executeQuery(query);
if(rs.next()){
setVisible(false);
new Dashboard();
}
else{
JOptionPane.showMessageDialog(null,"Invalid username or password");
setVisible(false);
}
}catch(Exception e){
e.getStackTrace();
}
}
else if(ae.getSource()==cancel){
setVisible(false);
}
}
public static void main(String[] args){
new Login();
}
}
Above one is the code for login page
Sir mera database ki table tho bnri h Lakin create database hotelmanagementsystem m error ara h
Error code: 1007 can't create database "hotelmanagementsystem" database exits
you already have a database with this name in your mysql
I also have same problem bt mera koi database create hua hi NH he isse phle
Sir me jab database create kiya to select * from login wali command run kari to workbench par bass username and password ki table bani ari hai lekin unki details ko ki admin aur 12345 thi vo show nhi hori
- using this command select * from login -> you can view the content of the table
- to create the table we use this command (create table tablename(columnname datatype);)
- Did you use insert command to insert values in the table?
@@codeforinterview sir jab insert into login values karke value insert kar rha hu to error dera hai no database selected , select the default DB to be used
@@munishgupta8186 use databasename;
run this command first
replace databasename with your actual database name before running this command
after that run your insert table command
Sir ma database ka table banata hu likn error aarah ha
Error: can’t create database hotelmanagementsystem; database exists what is this bro help me ????
your database with this name is already exist in the database
show databases;
you can use this command to check the existing databases in mysql
@@codeforinterview sir jab ma project run krta hon tou Added ni horahe database mein. Matlab Add Drivers wali class mein mne add kia likn pechay database mein add ni horhi sir plz help me.??
sir login or cancel button pr click krne pr kuch bhi actuon perform nhi ho rha ,click krne pr bhut sare exceptions aa rhe hai.Please help
please reply with the errors you are getting
Sir login button par click karne ke. Bad wo invisible ho Raha hai lekin aage ka page nahi dikha raha
Sir after doing this my cancel button is working properly but login button is not working what can i do sir
At 15:55 while adding the action listener to the cancel button he made a mistake change it to "cancel.addActionListener(this);" instead of "login.addActionListener(this);"
Thanks❤
But error is same
Sir my page is not opening after I login the dashboard page not opening...if I go to dashboard file from then I run it is opening..But when I click to login it's not...help me
what is the error you are getting on console?
@@codeforinterview there is no error but after clicking the login button the dashboard is opening but it's not showing anything...But when I separately open dashboard it's showing clearly...help me
@@codeforinterview help me sir...I want to submit that project
@@rutujathakur3219 please comment down below the code you have written inside dashboard class
@@codeforinterview
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package hotel.management.system;
import javax.swing.*;
import java.awt.*;
import java.sql.*;
/**
*
* @author Acer
*/
public class DashBoard extends JFrame {
DashBoard() {
setBounds(0, 0, 1550, 1000);
setLayout(null);
ImageIcon i1 = new ImageIcon(ClassLoader.getSystemResource("icons/third.jpg"));
Image i2 = i1.getImage().getScaledInstance(1550, 1000, Image.SCALE_DEFAULT);
ImageIcon i3 = new ImageIcon(i2);
JLabel image = new JLabel(i3);
image.setBounds(0, 0, 1550, 1000);
add(image);
JLabel text = new JLabel("THE THAKUR HOTEL WELCOMES YOU!!!");
text.setBounds(300, 80, 1000, 50);
text.setFont(new Font("Tahoma", Font.BOLD, 40));
text.setForeground(Color.black);
image.add(text);
JMenuBar mb = new JMenuBar();
mb.setBounds(0, 0, 1550, 30);
image.add(mb);
JMenu hotel = new JMenu("HOTEL MANAGEMENT");
hotel.setForeground(Color.BLUE);
hotel.setFont(new Font("Tahoma", Font.BOLD, 15));
mb.add(hotel);
JMenuItem reception = new JMenuItem("RECEPTION");
reception.setForeground(Color.RED);
reception.setFont(new Font("Tahoma", Font.BOLD, 15));
hotel.add(reception);
JMenu admin = new JMenu("ADMIN");
admin.setForeground(Color.BLUE);
admin.setFont(new Font("Tahoma", Font.BOLD, 15));
mb.add(admin);
JMenuItem addempolyee = new JMenuItem("ADD EMPOLYEE");
addempolyee.setForeground(Color.RED);
addempolyee.setFont(new Font("Tahoma", Font.BOLD, 15));
admin.add(addempolyee);
JMenuItem addrooms = new JMenuItem("ADD ROOMS");
addrooms.setForeground(Color.RED);
addrooms.setFont(new Font("Tahoma", Font.BOLD, 15));
admin.add(addrooms);
JMenuItem adddrivers = new JMenuItem("ADD DRIVERS");
adddrivers.setForeground(Color.RED);
adddrivers.setFont(new Font("Tahoma", Font.BOLD, 15));
admin.add(adddrivers);
setVisible(true);
while(true){
text.setVisible(false);
try{
Thread.sleep(500);
}catch (Exception e) {
e.printStackTrace();
}
text.setVisible(true);
try{
Thread.sleep(500);
}catch (Exception e) {
e.printStackTrace();
}
}
}
public static void main(String[] args){
new DashBoard();
}
}
sir aapne jaar file kaha per di hai....
Sir, when I implements ActionListener then login class gets error why?
What is the error?
@@codeforinterview sir i try more then two three times allready error is gone but in lecture 5 I set jar file but didn't work it I complete lecture 5 at last give me error all class are working good but conn class didn't work?
@@ankitray4873 What is the error?
@@codeforinterview java. Lang. Classnotfoundexception : com. Mysql. Cj. Jdbc. Driver
@@codeforinterview sir cancel button is working bot login button is not working it give an error
Unable to add jar file what to do ?
please tell me also if you've found it
Bhai yaar communication linking failure between database and the project in intellijay kahi koi solution nahi mil raha ab yeah mat kahiya i have not used intellij idea for java javal. Sql. Communication failure unknown database and cannot connect in intellijay 20 tarik se pehle solve kar saktey ho toh help kardo because myndeadline is on 20 may
are you using wampserver/xammpserver?
@@codeforinterview no but yes I have installed it on my pc
@@shashwat4299 uninstall it and it will resolve your issue
@@codeforinterview i have done this now but still the problem exist what should I do now i am literallly feeling helpless as there is no one to guide but thanks for the reply keep making good videos
@@shashwat4299 make sure your mysql is up and running
press window + r
type services.msc
search for mysql
and make sure it is up and running
Sir getting error as Null Pointer Exception
please comment down below the full exception you are getting
sir my sql connect krne me problem aa rhi hai.
What is the issue?
"c1.s" is null this error is comming in login file
you have an error in the conn class, do you have any other error on console?
maybe mysql connector isnt added to classpath
Ye zip file laptop ma download ni hori
esa nhi hoga, try again
Are bro source code different hai jo aapne description mai upload kiya hai🙂😭
Do you have issue in the code?
17:18 now im getting the same error class does not have a main method , before this video in part 4 every thing was running smooth but now it isnt (is there any way can i contact you? whatsapp discord,etc?)
don't run conn class, it does not have the main method.
@@codeforinterview i can not run login dashboard too they all show the same error
@@pravingouda568 go inside the login class, right click on the code and click on run application
@@codeforinterview so it's isn't my file issue right?? Some of my friends are saying that I miss placed my file somewhere
password or username dalna k baad error ara h
Java.lang.classnotfoundexception:conn.mysql.cj.jdbc.Driver
or mene mysql-connector-java isko bhi library main paste kr diya fir bhi
your driver is wrong, com.mysql.cj.jdbc.Driver
replace conn with com
@@codeforinterview thanks vo problem to solve ho gayi but ab ek nayi problem aa rahi hain or vo yeh hain
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
@@MohitSingh-ki7mm you have to mention the same password in your conn class which you use to open mysql
maine password bilkul same dal rakha hain bhai yrr fir bhi
Sir login button pe click karne ke baad error aa raha hai
What is the error?
Problem Solve huvi sir MySQL ka password galat. Dala tha
@@Karishmashaikh-bo6vl Got it.
Your old account got deleted? :((
Yes bro
Bhai ka channel suspend ho gaya tha kyuki unka system hack ho gaya tha to CZcams community guidelines ke against sb kr rhe thay jinhone bhi hack kiya tha.
Or inn sb ke vjh se bhaiya ka channel delete ho gaya 😥😢
Hi Rishab, thanks for the concern. Yeah! old channel got deleted in an unfortunate incident.
Sir iska database kaise bnega
I have taught everything in the video, kindly watch the video
Sir plz reply krain apko dm text kia mne
replied, please check
Sir plz dm reply krain 🙏🏻
done, please check
Sir dm msg kia reply plz 🥺
replied
@@codeforinterview thanks 😊
main ye project es chainla se hi start kiya tha magar main ne esko chhod diya kyu ki mujhe sahi se dikh hi nahi raha tha or mere sab
bhai tu apne comment bhi check kr liya kr
theek hai bhai 😂
@@codeforinterview bhai comment dekh to leta yrr chal main dobara likh deta hun main yeh keh raha tha mera user id and password bilkul theek hain fir bhi vo same error throwen kr raha hain
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
ab iska koi solution de de bhai maine insta pr bhi comment kiya
@@MohitSingh-ki7mm
1) make sure you don't have multiple mysql installed in your system.
2) You need to mention the same password which you use to login in mysql
3) make sure your mysql is running on port 3306
4) Run windows + r, type services.msc, click enter, search for mysql, make sure it is up and running
I need you help....
What help do you need?
sir I'm gettin error Classnot found Exception ,I'm adding jar file but they still
java.lang.ClassNotFoundException: con.cj.mysql.jdbc.Driver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:375)
at hotel.management.system.Conn.(Conn.java:22)
at hotel.management.system.Login.actionPerformed(Login.java:73)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1972)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2313)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
plz help me sir
you need to add a jar file in the project which is mysql-connector-java, add the same under the libraries section of the project
Sir login or password dalna k baad ab bhi error ara h
Java.sql.sqlnontransientconnectionexpection:cannot load connection class because of underlying exception :com.mysql.cj.exceptions.wrongargunentexception:malformed database url, failed to parse tha main url section.
comment down below the code you have written inside conn class
@@codeforinterview package hotel.management.system;
Import java.sql.*;
Public class conn{
Connection c;
Statement s;
Conn(){
Try{
Class.forName("com.mysql.cj.jbdc.Driver");
C=Driver Manager.getConnection("jdbc:mysql://localhost:///hotelmanagementsystem",root","codeforinterview");
S=c.creatstatement();
}
Catch (Exception e){
e.printStackTrace();
}
}
}
@@simeechaudhary3135 your driver name is wrong
com.mysql.cj.jbdc.Driver
com.mysql.cj.jdbc.Driver
jdbc instead of jbdc
@@codeforinterview sir ab bhi ya hi error ara h
@@simeechaudhary3135 comment down below the error
Sir mera password or username dalna k baad error ara h
Java.lang.classnotfoundexception:conn.mysql.cj.jdbc.Driver
you need to include the jar file in the project which is mysql-connector-java. Include it under the libraries section like I did in the video
Sir apko instagram pr message kia kindly check krain plz sir 🙏🏻
replied, please check
I have messaged you on instagram plz check
sir i have messaged you on instagram please check
replied, please check
@@codeforinterview thank you