Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Loading...
User Settings
close menu
Welcome to Scribd!
Upload
Read for free
FAQ and support
Language (EN)
Sign in
0 ratings
0% found this document useful (0 votes)
3 views
Web7 2100290110077
Uploaded by
Khushi Pachauri
AI-enhanced
Assignment
Copyright:
© All Rights Reserved
Available Formats
Download
as PDF or read online from Scribd
Download
Save
Save web7_2100290110077 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Web7 2100290110077
Uploaded by
Khushi Pachauri
0 ratings
0% found this document useful (0 votes)
3 views
6 pages
AI-enhanced title
Document Information
click to expand document information
Assignment
Original Title
web7_2100290110077
Copyright
© © All Rights Reserved
Available Formats
PDF or read online from Scribd
Share this document
Share or Embed Document
Sharing Options
Share on Facebook, opens a new window
Facebook
Share on Twitter, opens a new window
Twitter
Share on LinkedIn, opens a new window
LinkedIn
Share with Email, opens mail client
Email
Copy link
Copy link
Did you find this document useful?
0%
0% found this document useful, Mark this document as useful
0%
0% found this document not useful, Mark this document as not useful
Is this content inappropriate?
Report
Assignment
Copyright:
© All Rights Reserved
Available Formats
Download
as PDF or read online from Scribd
Download now
Download as pdf
Save
Save web7_2100290110077 For Later
0 ratings
0% found this document useful (0 votes)
3 views
6 pages
Web7 2100290110077
Uploaded by
Khushi Pachauri
AI-enhanced title
Assignment
Copyright:
© All Rights Reserved
Available Formats
Download
as PDF or read online from Scribd
Save
Save web7_2100290110077 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download as pdf
Jump to Page
You are on page 1
of 6
Search inside document
Fullscreen
EXP. 1. install a database (Mysql or Oracle). Create a table which should contain the following fields: name, password, email-id, and phone number. Write a java program/serviet/JSP to connect to that database and extract data from the tables and display them. Insert the details of the users who register with the website, whenever a new user clicks the submit button on the registration page. CODE ‘EMPLOYEE TABLE CREATE TABLE ‘employee’ ( ‘id! int(3) NOT NULL AUTO_INCREMENT, first_name’ varchar(20) DEFAULT NULL, “Yast_name* varchar(20) DEFAULT NULL, username” varchar(250) DEFAULT NULL, “password” varchar(20) DEFAULT NULL, address’ varchar(45) DEFAULT NULL, ‘contact’ varchar(45) DEFAULT NULL, PRIMARY KEY (‘id’) ) Employee.java package net javaguides,jsp.jdbe.bean; import java.io.Serializable; public class Employee implements Serializable { private static final long serialVersionUID = 1 L; private String firstName; private String lastName; private String username; private String password; private String address; private String contact; Public String getFirstName() { return firstName; ) Public void setFirstName(String firstName) { this.firstName = firstName; ) public String getLastName() { return lastName; ) public void setLastName(String lastName) { this.lastName = lastName; , public String getUsername() { return username; ) public void setUsername(String usermame) { this. username = username; ,public String getPassword() { return password; } Public void setPassword(String password) { this.password = password; J public String getAddress() { return address; } public void setAddress(String address) { address = address; } public String getContact() { return contact; ) public void setContact(String contact) { this.contact = contact; ) ) -EmployeeDao.java package net javaguides jsp.jdbc database; import java.sql.Connection; import java.sql.OriverManager; import java.sql.Preparedstatement; import java.sql.SQLException; import net javaguides.sp.jdbe.bean.Employee; public class EmployeeDao { public int registerEmployee(Employee employee) throws ClassNotFoundException { String INSERT_USERS_SQL = "INSERT INTO employee" + " (id, first_name, last_name, username, password, address, contact) VALUES " + "02,2,22 22" int result =0; Class.forName(""com.mysql,jdbe.Driver"); try (Connection connection = DriverManager getConnection("jdbc:mysql://localhost:3306/employees?useSSi=false”, "root" 1/ Step 2:Create a statement using connection object Preparedstatement preparedStatement = connection. prepareStatement(INSERT_USERS_SQL)) { preparedstatement.setint(1, 1); preparedStatement.setString(2, employee.getFirstName());preparedstatement.setString(3, employee.getLastName()); preparedStatement.setString(4, employee.getUsername()); preparedstatement.setString(5, employee.getPassword()); preparedstatement.setString(6, employee.getAddress()); preparedstatement.setString(7, employee.getContact()); System. out.printin(preparedStatement); // Step 3: Execute the query or update query result = preparedStatement.executeUpdate(); } catch (SQLException e) { // process sql exception printsQLexception(e); ) return result; , private void printSQLexception(SQLException ex) { for (Throwable e: ex) { if (e instanceof SQLException) { e.printStackTrace(System.err); system.err.printin("sastate: " + ((SQLException) e).getsQLstate()); System.err.printin("Error Code: " + ((SQLException) e).getErrorCode()); System.err.printin("Message: " + e.getMessage()); Throwable t = ex.getCause(); white (t f= null) ( System.out.printin( "Cause: " +t); tgetCause(); EmployeeServiet.javs package net javaguides.employeemanagement.web; import java.io.|OException; import javax.serviet ServietException; import javax.servlet.annotation. WebServet; import javax.serviet.http.HttpServiet; import javax.servlet:http-HttpServietRequest; import javax.serviet.http.HttpServletResponse; import net javaguides.employeemanagement.dao.€mployeeDao; import net javaguides.employeemanagement.model.Employee; @webServiet("/register")public class EmployeeServlet extends HttpServiet { private static final long serialversionUID = 1 L; private EmployeeDao employeeDao; public void init() { ‘employeeDao = new EmployeeDao\); } protected void doPost(HttpServietRequest request, HttpServietResponse response) throws ServletException, IOException { String firstlvame = request getParameter("firstName"); String lastName = request.getParameter("lastName"); String username = request.getParameter("username");, String password = request.getParameter("password"); String address = request.getParameter("address"); String contact = request.getParameter("contact"); Employee employee = new Employee(); ‘employee.setFirstName(firstName); ‘employee.setLastName(lastName); ‘employee.setUsername(username); employee.setPassword(password); ‘employee.setContact(contact); employee.setAddress(address); wyt employeeDao.registerémployee(employee); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } response.sendRedirect("‘employeedetalls.jsp"); } } mployeeregister.jsp
insert title heres/title>
Employee Register Forms/hi>
First Name
>
Last Name
te <
UserNames/td>
Password
addresse/td> «
Contact No
Create an employeedetails.isp
shead>
insert title here
User successfully registered!