Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need a Hotel Management System Project in Java and MySQL, console based. the database code should be like this DATABASE CONNECTIVITY IN JAVA WITH

I need a Hotel Management System Project in Java and MySQL, console based.

the database code should be like this

DATABASE CONNECTIVITY IN JAVA WITH MYSQL DATABASE 1 | P a g e package database.connectivity; import java.sql.*; import java.util.Scanner; public class DatabaseConnectivity { public static void main(String[] args) { Scanner user_input = new Scanner(System.in); System.out.println("1. Display All records"); System.out.println("2. Add New record"); System.out.println("3. Delete record"); System.out.println("4. Search record"); System.out.println(""); System.out.println("Enter Your Choice : "); String choice = user_input.next(); int ch = Integer.parseInt(choice); if (ch==1) { // TO DISPLAY ALL RECORDS try { Connection dbCon =DriverManager.getConnection("jdbc:mysql://localhost:3306/school","root", "saffron"); Statement stmt = dbCon.createStatement(); String query ="select * from student2"; ResultSet rs = stmt.executeQuery(query); while(rs.next()){ System.out.println("Name : "+ rs.getString(1)); System.out.println("Class : " + rs.getString(2)); System.out.println("Marks : "+ rs.getString(3)); } } catch(SQLException ex) { System.out.println(ex.getMessage()); } } else if (ch==2) { // TO ADD NEW RECORD IN MYSQL TABLE try { System.out.println("Enter Student Name : "); String sname = user_input.next(); System.out.println("Enter Class : "); String grade = user_input.next(); DATABASE CONNECTIVITY IN JAVA WITH MYSQL DATABASE 2 | P a g e System.out.println("Enter Marks : "); String marks = user_input.next(); System.out.println(""); Connection dbCon =DriverManager.getConnection("jdbc:mysql://localhost:3306/school","root", "saffron"); Statement stmt = dbCon.createStatement(); String sql = "INSERT INTO student2(sname,grade,marks)"+"VALUES('"+sname+"','"+grade+"','"+marks+"');"; stmt.executeUpdate(sql); System.out.println(" SUCCESS! "); } catch(SQLException ex) { System.out.println(ex.getMessage()); } } else if (ch==3) { // TO DELETE RECORD FROM MYSQL TABLE try { System.out.println("Enter Student Name to Delete : "); String sn = user_input.next(); System.out.println(""); Connection dbCon =DriverManager.getConnection("jdbc:mysql://localhost:3306/school","root", "saffron"); Statement stmt = dbCon.createStatement(); String sql= "Delete from student2 where sname='"+sn+"';"; stmt.executeUpdate(sql); System.out.println(" RECORD DELETED SUCCESSFULLY! "); } catch(SQLException ex) { System.out.println(ex.getMessage()); } } else if (ch==4) { DATABASE CONNECTIVITY IN JAVA WITH MYSQL DATABASE 3 | P a g e // TO SEARCH FOR ANY PARTICULAR RECORD FROM MYSQL TABLE try { System.out.println("Enter Student Name to Search : "); String sn = user_input.next(); System.out.println(""); Connection dbCon =DriverManager.getConnection("jdbc:mysql://localhost:3306/school","root", "saffron"); Statement stmt = dbCon.createStatement(); String sql= "Select * from student2 where sname='"+sn+"';"; ResultSet rs = stmt.executeQuery(sql); while(rs.next()){ System.out.println("Name : "+ rs.getString(1)); System.out.println("Class : " + rs.getString(2)); System.out.println("Marks : "+ rs.getString(3)); } } catch(SQLException ex) { System.out.println(ex.getMessage()); } } else { System.out.println("Invalid Choice!"); } } }

I need for Class 12 project

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions

Question

List and describe three behavioral leadership theories.

Answered: 1 week ago