Jsp

Jsp Mysql Ajax Project

This Jsp Mysql Ajax Project will teach you how to do basic database functions that are CREATE RETIEVE UPDATE and DELETE. using Mysql Database using Ajax. The INSERT, SELECT, UPDATE and DELETE statements can be used in any database system, because this is support by all relational database systems.The project is very helpful for learn Ajax technology.

 

All the libraries i put in to one folder which name is components. i attached the link below you will be able to download.

https://drive.google.com/drive/folders/1Wn6kACTV24qFw6ztKUcfQ9CsQUF9PFF1

In order to do the project download the related jar files for connect with Ajax json simple.jar. In order to download  the jar go to the  respective website to do the task click link and download them Click here.

Index.php

we are going to implemented all crud operations to  get the help of Ajax without reload the pages.

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
        <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
        <link rel="stylesheet" href="//cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
    </head>
    <body>
        
        <nav class="navbar navbar-dark bg-primary">
            <h3 style="color: white">Student Management System Crud Using Jsp Ajax</h3>
        </nav>
        
        </br>
        <div class="row">
         
            <div class="col-sm-4">
                <div class="container">
                    
                    <form id="frmStudent" name="frmStudent">
                       
                        <div class="form-group" align="left">
                            <label>Student Name</label>
                            <input type="text" name="stname" id="stname" class="form-control" placeholder="StudentName" size="30px" required>
                        </div>
                        
                        <div class="form-group">
                            <label>Course</label>
                            <input type="text" name="course" id="course" class="form-control" placeholder="Course" size="30px" required>
                        </div>
                        
                         <div class="form-group">
                            <label>Fee</label>
                            <input type="text" name="fee" id="fee" class="form-control" placeholder="Fee" size="30px" required>
                        </div>
                        
                         <div class="form-group" align="right">
                             <button type="button" class="btn btn-info" id="save" >

Add records :- when you get add request from the Ajax call

add.jsp

<%@page import="java.sql.DriverManager"%>
<%@page import="org.json.simple.JSONObject"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="org.json.simple.JSONArray"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%  

JSONArray list = new JSONArray();

String studname = request.getParameter("stname");
String course = request.getParameter("course");
String fee = request.getParameter("fee");

Connection con;
PreparedStatement pst;
ResultSet rs;


JSONObject obj = new JSONObject();

Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/jspstudent","root","");
pst = con.prepareStatement("insert into records (stname,course,fee)values(?,?,?)");
pst.setString(1, studname);
pst.setString(2, course);
pst.setString(3, fee);
pst.executeUpdate();
obj.put("name", "success");
list.add(obj);
out.println(list.toJSONString());
out.flush();

%>

View the Record from database to datatable:-  when you get view request from the Ajax call

all_students.jsp

<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="org.json.simple.JSONObject"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="org.json.simple.JSONArray"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%  
JSONArray list = new JSONArray();
Connection con;
PreparedStatement pst;
ResultSet rs;

Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/jspstudent","root","");

String query = "select * from records";

Statement stmt = con.createStatement();

rs = stmt.executeQuery(query);


while(rs.next())
{
    JSONObject obj = new JSONObject();
    String id = rs.getString("id");
    String name = rs.getString("stname");
    String course = rs.getString("course");
    String fee = rs.getString("fee");
    
    obj.put("name", name);
    obj.put("course", course);
    obj.put("fee", fee);
    obj.put("id", id);
    list.add(obj);
}

out.print(list.toJSONString());
out.flush();

%>

edit_return.jsp

<%@page import="org.json.simple.JSONObject"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="org.json.simple.JSONArray"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%
JSONArray list = new JSONArray();
Connection con;
PreparedStatement pst;
ResultSet rs;

Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/jspstudent","root","");

String id = request.getParameter("id");

pst = con.prepareStatement("select id,stname,course,fee from records where id = ?");

pst.setString(1, id);
rs = pst.executeQuery();

if(rs.next()==true)
{
    String id1 = rs.getString(1);
    String stname = rs.getString(2);
    String scourse = rs.getString(3);
    String sfee = rs.getString(4);
     JSONObject obj = new JSONObject();
     
     obj.put("id",id1);
     obj.put("stname",stname);
     obj.put("scourse",scourse);
     obj.put("sfee",sfee);
     list.add(obj);
     
    
}

out.print(list.toJSONString());
out.flush();




%>

update.jsp

<%@page import="java.sql.DriverManager"%>
<%@page import="org.json.simple.JSONObject"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="org.json.simple.JSONArray"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%
    
JSONArray list = new JSONArray();


String stid = request.getParameter("studentid");
String studname = request.getParameter("stname");
String course = request.getParameter("course");
String fee = request.getParameter("fee");

Connection con;
PreparedStatement pst;
ResultSet rs;


JSONObject obj = new JSONObject();

Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/jspstudent","root","");
pst = con.prepareStatement("update records set stname = ?, course= ? , fee= ? where id = ?");
pst.setString(1, studname);
pst.setString(2, course);
pst.setString(3, fee);
pst.setString(4, stid);
pst.executeUpdate();
obj.put("name", "success");
list.add(obj);
out.println(list.toJSONString());
out.flush();




%>

Delete.jsp

<%@page import="java.sql.DriverManager"%>
<%@page import="org.json.simple.JSONObject"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="org.json.simple.JSONArray"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%
JSONArray list = new JSONArray();
String stid = request.getParameter("id");
Connection con;
PreparedStatement pst;
ResultSet rs;
JSONObject obj = new JSONObject();
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/jspstudent","root","");
pst = con.prepareStatement("delete from records where id = ?");
pst.setString(1, stid);
pst.executeUpdate();
obj.put("name", "success");
list.add(obj);
out.println(list.toJSONString());
out.flush();
%>

i have attached the video link below. which will do this tutorials step by step.

 

 

admin

Recent Posts

Java Beans

A Java Bean is a reusable software component that follows a specific set of conventions.…

12 hours ago

Java String Methods

Java provides a rich set of built-in methods for handling String operations efficiently. Since strings…

13 hours ago

Java Developer Jobs

Java remains one of the most in-demand programming languages worldwide, powering everything from enterprise applications…

13 hours ago

Converting Integer to String in Java

Java provides multiple ways to convert an integer (int) to a string (String). Whether you're…

13 hours ago

JSP to JSP Communication: A Complete Guide to Dynamic Java Web Development

Java Server Pages (JSP) is a powerful technology used to develop dynamic web applications by…

6 days ago

Which Frontend Framework to Use with Spring Boot?

Spring Boot is a powerful backend framework for developing Java-based web applications. Pairing it with…

7 days ago