Home > Enterprise >  Database for making employee details
Database for making employee details

Time:11-14

In below File I done some coding to make a jdbc connection. And I am using a xampp server for that.

ConnectionProvider.java

package com.employeerecord.helper;

import java.sql.*;

public class ConnectionProvider {
//method GetConnection
    private static Connection connection;
    public static Connection getConnection() {
        try {
            //if connection is null then only it get created
            if(connection==null) {
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection("jdbc:mysql://localhost/emprecord","root","");  //Driver for Connection
            }
        } catch(Exception e) {
            e.printStackTrace();
        }
        return connection;
    }
}

In Below code I make a frontend of the jsp page and put some dummy values. But I'am getting an error of "ConnectionProvider cannot be resolved" and does not having an connection.

index.jsp

<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Home</title>

<!-- All CSS -->

<link
    href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
    rel="stylesheet"
    integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
    crossorigin="anonymous">
<link href="CSS/style.css" rel="stylesheet">

<!-- All JS -->

<script
    src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"
    integrity="sha384-7 zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB"
    crossorigin="anonymous"></script>
<script 
    src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" 
    integrity="sha384-QJHtvGhmr9XOIpI6YVutG 2QOK9T ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" 
    crossorigin="anonymous"></script>

</head>
<body>
<%  Connection connection =  ConnectionProvider.getConnection();
    out.println(connection);
    %>
<%@include file="navbar.jsp" %><br><br><br>
                    <!-- Table -->
    <div >
        <div >
        <h3>All Employees In Our Company Are Listed Here</h3>
            <table >
                <thead>
                    <tr>
                        <th scope="col"> EmployeeID </th>
                        <th scope="col"> Name </th>
                        <th scope="col"> Skills </th>
                        <th scope="col"> Address </th>
                        <th scope="col"> Gender </th>
                        <th scope="col"> Salary </th>
                        <th scope="col"> BirthDate </th>
                        <th scope="col"> Edit </th>
                        <th scope="col"> Delete </th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>1</td>
                        <td>xyz</td>
                        <td>Java</td>
                        <td>abc</td>
                        <td>Male</td>
                        <td>40,000</td>
                        <td>11/11/0000</td>
                        <td>Edit</td>
                        <td>Delete</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</body>
</html>

Error

I'am doing a connection between the jsp file and mysql server using xampp. Erron I am Getting

CodePudding user response:

I think you haven't imported ConnectionProvider you should add it

<%@page import="com.employeerecord.helper.ConnectionProvider"%>

CodePudding user response:

In your index.jsp, There is no import for ConnectionManager.

I recommend that you don't use Connection in the view.

I wish you could separate the view and the database area.

Here is reference for separating the view and the database area.

https://www.quora.com/Why-are-separate-views-necessary-in-database-applications

  • Related