Now we focus on JDBC Operations – Insert Records and Display.
Before continuing, go through this earlier post to create the database table.
Detailed Description of JDBC Operations – Insert Records and Display
Here we insert records in the Exam table using a JavaBean. For this purpose, define a method addUser_1() with the following signature.
String addUser_1(UserBean userBean);
Also, perform the following tasks.
(i) Create a Java class UserBean with the following private variables – userId, password, userName, userType, incorrectAttempts, and lockStatus. Also, define getters, and setters for each variable.
(ii) Obtain the Connection object using the getDBConnection() method. After that, insert a record using the above method that returns a String. When the record is successfully inserted, the return value should be “Success”. Otherwise, the return value should be “fail”.
(iii) Call the addUser_1() method from the main() method. Check the inserted value using SqlPlus at the command line.
Similarly, create a method addUser_2(), with precisely the same parameters as taken by the addUser_1() method. Also, it should perform the same tasks. However, it should insert a record only when the value of lockStatus is 0.
Further, create a method getUsers() with the following signature.
ArrayList<UserBean> getUsers(String userType);
This method should perform the following tasks.
(i) Obtain the Connection object using the getDBConnetion() method and retrieve all records with the specified user_type.
(ii) Add all these records to an ArrayList and return that ArrayList.
(iii) Within the main() method, retrieve all the specified records and display these records.
Likewise, create a method storeAllRecords() that returns an ArrayList containing all records from the Exam table.
Another method getNames() need to be created with the following signatures:
String[] getNames();
This method should return an array of strings containing user names. Display the user names by calling this method from the main() method.
Further Reading
Understanding Enterprise Java Beans
- AI
- Android
- Angular
- ASP.NET
- Augmented Reality
- AWS
- Bioinformatics
- Biometrics
- Blockchain
- Bootstrap
- C
- C#
- C++
- Cloud Computing
- Competitions
- Courses
- CSS
- Cyber Security
- Data Science
- Data Structures and Algorithms
- Data Visualization
- Datafication
- Deep Learning
- DevOps
- Digital Forensic
- Digital Trust
- Digital Twins
- Django
- Docker
- Dot Net Framework
- Drones
- Elasticsearch
- ES6
- Extended Reality
- Flutter and Dart
- Full Stack Development
- Git
- Go
- HTML
- Image Processing
- IoT
- IT
- Java
- JavaScript
- Kotlin
- Latex
- Machine Learning
- MEAN Stack
- MERN Stack
- Microservices
- MongoDB
- NodeJS
- PHP
- Power Bi
- Projects
- Python
- Quantum Computing
- React
- Robotics
- Rust
- Scratch 3.0
- Shell Script
- Smart City
- Software
- Solidity
- SQL
- SQLite
- Tecgnology
- Tkinter
- TypeScript
- VB.NET
- Virtual Reality
- Web Designing
- WebAssembly
- XML