{"id":24703442,"url":"https://github.com/ajitagupta/student-management-system","last_synced_at":"2025-03-22T04:43:07.304Z","repository":{"id":227843332,"uuid":"771642763","full_name":"ajitagupta/student-management-system","owner":"ajitagupta","description":"Advanced Java: Student CRUD API with MySQL database","archived":false,"fork":false,"pushed_at":"2024-05-20T09:56:01.000Z","size":3934,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-27T05:55:11.549Z","etag":null,"topics":["advanced-java","crud","database-connection","java","jdbc","learning-java","mysql-database","software-patterns"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ajitagupta.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-13T17:16:24.000Z","updated_at":"2025-01-17T17:46:37.000Z","dependencies_parsed_at":"2024-03-15T12:46:08.787Z","dependency_job_id":"6c211943-b430-4fb7-9d65-3f6b06ded191","html_url":"https://github.com/ajitagupta/student-management-system","commit_stats":null,"previous_names":["ajitagupta/student-management-system"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajitagupta%2Fstudent-management-system","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajitagupta%2Fstudent-management-system/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajitagupta%2Fstudent-management-system/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajitagupta%2Fstudent-management-system/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajitagupta","download_url":"https://codeload.github.com/ajitagupta/student-management-system/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244907379,"owners_count":20529851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["advanced-java","crud","database-connection","java","jdbc","learning-java","mysql-database","software-patterns"],"created_at":"2025-01-27T05:55:22.414Z","updated_at":"2025-03-22T04:43:07.284Z","avatar_url":"https://github.com/ajitagupta.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Student Management System\nThis is a student CRUD API project with JDBC connection to a MySQL 8.0 database. It allows to create new, read, update, and delete existing student data. \n\nTo get started, execute the following:\n\n1) Download [Eclipse](https://www.eclipse.org/downloads/)\n2) Download a SQL client like [MySQL Workbench](https://dev.mysql.com/downloads/workbench/)\n3) Run sql.sql to set up a database\n4) Start using our menu-driven app\n\n## Pattern: Tree-package-structure\n\nPackages should be cohesive collections of classes. That would minimize coupling between classes that should not be coupled because they pertain to different features. In the package-by-layer approach, packages have high cohesion and a low degree of coupling between packages. \n\nOur code follows common convention of organizing itself in different subpackages, each for a different child-layer: `dao, db, main, and pojo`, whereby `com.example` is the parent of them all. Hence, the name tree structure.\n\n![Tree-package-structure](https://i.ibb.co/7p9N5Lc/tree-package-structure.png \"Tree-package-structure\")\n\n\n## Database Connection with JDBC\n\nJDBC (Java Database Connectivity) is the Java API that manages connecting to a database, issuing queries and commands, and handling result sets obtained from the database.\n\nThe steps for connecting to a database with JDBC are as follows:\n\n1. Install or locate the database you want to access.\n2. Include the JDBC library.\n3. Ensure the JDBC driver you need is on your classpath.\n4. Use the JDBC library to obtain a connection to the database.\n5. Use the connection to issue SQL commands.\n6. Close the connection when you are finished.\n\n\nAs a developer, you can use JDBC to interact with a database from within a Java program. JDBC acts as a bridge from your code to the database. JDBC is the common API that your application code interacts with. Beneath that is the JDBC-compliant driver for the database you are using as shown in the figure below:\n\n![JDBC](https://i.ibb.co/pZPSnYD/what-is-jdbc-fig2-100927560-large.webp \"JDBC\")\n\nSource: InfoWorld\n\nWhile JDBC is sufficient for simpler applications, most developers will eventually look to the Jakarta Persistence API (formerly the Java Persistence API) to develop a more formal data access layer.\n\n## Pattern: Singleton\n\nThere are many objects we only need one of: thread pools, caches, dialog boxes, objects that handle preferences and registry settings, objects used for logging, and objects that act as device drivers to devices like printers and graphics cards. In fact, for many of these types of objects, if we were to instantiate more than one we'd run into all sorts of problems like incorrect program behavior, overuse of resources, or inconsistent results.\n\n\u003cblockquote\u003e\nThe Singleton Pattern ensures a class has only one instance, and provides a global point of access to it. Whenever you need an instance, just query the class and it will hand you back the single instance.\n\u003c/blockquote\u003e\n\n[*Head First Design Patterns*](https://www.oreilly.com/library/view/head-first-design/9781492077992/)\n\nIn short, a Singleton is a one-of-a-kind object for which only one instance is required. Following this best practice we put all our database code into one class. The so-called resulting *Singleton* class `CP.java` is as follows:\n\n```\npublic class CP {\n\n\tstatic Connection conn;\n\t\n\tpublic static Connection createc() throws SQLException {\n\t\t\n\t\t//load driver class\n\t\t\n\t\ttry {\n\t\t\tClass.forName(\"com.mysql.cj.jdbc.Driver\");\n\t\t\t\n\t\t\t//create connection\n\t\t\t\n\t\t\tString user=\"root\";\n\t\t\tString password=\"root\";\n\t\t\tString url=\"jdbc:mysql://localhost:3306/studentdata\";\n\t\t\t\n\t\t\tconn=DriverManager.getConnection(url, user, password);\n\t\t} catch (ClassNotFoundException e) {\n\t\t\n\t\t\te.printStackTrace();\n\t\t}\n\t\treturn conn;\n\t\t\n\t\t\n\t}\n\t\n}\n```\n\nHere, we execute an SQL query using `PreparedStatement` and SQL-argument-placeholders. Since this action has to be repeated at many occasions (CRUD) it makes sense to place the code inside a Singleton.\n\n## Pattern: Data Access Object (DAO)\n\nThe DAO is responsible for interfacing with the database. It implements methods for saving/retrieving/deleting entities.\n\n## Pattern: POJO Class\n\nTo enable mapping between Java code and database we create a Plain Old Object Class (POJO). For each table there is a corresponding POJO class. This is the convention.\n\nFor our case we just need one Student POJO since we have only one table `students` in our database. It contains a default and a parameterized constructor, getter / setter methods, and a toString method.\n\n## Screenshots\n\n### (C)reate\n\n#### Eclipse Console\n![Create function](https://i.ibb.co/thHQK8B/Add.png \"Create function\")\n\n#### MySQL Workbench\n![New record inside MySQL database](https://i.ibb.co/L1jm3Gg/database.png \"New record inside MySQL database\")\n\n### (R)ead\n\n#### Eclipse Console\n![Read function](https://i.ibb.co/7VW6Zmj/Display.png \"Read function\")\n\n\n### (U)pdate\n\n#### Eclipse Console\n![Update function](https://i.ibb.co/PrT6xzK/Update.png \"Update function\")\n\n#### MySQL Workbench\n![Updated record inside MySQL database](https://i.ibb.co/gmhBBC8/database-updated.png \"Updated record inside MySQL database\")\n\n\n### (D)elete\n\n#### Eclipse Console\n![Delete function](https://i.ibb.co/CJVqmq1/Delete.png \"Delete function\")\n\n#### MySQL Workbench\n![Empty MySQL database](https://i.ibb.co/BjB9jY0/database-entrydeleted.png \"Empty MySQL database\")\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajitagupta%2Fstudent-management-system","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajitagupta%2Fstudent-management-system","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajitagupta%2Fstudent-management-system/lists"}