JSP Insert
Sat Nov 16 2024 04:08:20 GMT+0000 (Coordinated Universal Time)
Saved by
@login123
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql., javax.sql." %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Connection conn =null;
PreparedStatement stmt = null;
try{
int id = Integer.parseInt(request.getParameter("id"));
String name = request.getParameter("name");
String position = request.getParameter("position");
float salary = Float.parseFloat(request.getParameter("salary"));
Class.forName("com.mysql.cj.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/Vijaya","root","Saimanish@2004");
String sql = "INSERT INTO employees (id,name,position,salary) VALUES (?, ?, ?, ?)";
stmt = conn.prepareStatement(sql);
stmt.setInt(1,id);
stmt.setString(2, name);
stmt.setString(3, position);
stmt.setFloat(4, salary);
int rows = stmt.executeUpdate();
if (rows > 0) {
out.println("<p>Employee row inserted successfully!</p>");
} else {
out.println("<p>Error: Employee row cannot be inserted.</p>");
}
} catch (Exception e) {
out.println("Error: " + e.getMessage());
}
%>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="update.jsp" method="post"><br>
Id:<input type="text" name="id" required><br>
Name:<input type="text" name="name" required><br>
Position:<input type="text" name="position" required><br>
Salary:<input type="text" name="salary" required><br>
Submit:<input type="submit"><br>
</form>
</body>
</html>
content_copyCOPY
Comments