{"id":19933436,"url":"https://github.com/kinshuk-code-1729/jdbc-crud","last_synced_at":"2026-05-12T18:32:35.409Z","repository":{"id":223644392,"uuid":"761119185","full_name":"kinshuk-code-1729/JDBC-crud","owner":"kinshuk-code-1729","description":"This repository contains various snippets of CRUD operations using JDBC.","archived":false,"fork":false,"pushed_at":"2024-02-23T18:56:40.000Z","size":21,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-12T01:51:24.464Z","etag":null,"topics":["crud-operation","java","java-database-connectivity","jdbc","mysql-database"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kinshuk-code-1729.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-02-21T09:22:32.000Z","updated_at":"2024-02-21T20:30:36.000Z","dependencies_parsed_at":"2024-02-23T19:44:29.939Z","dependency_job_id":"634f2833-a190-4d58-ac94-16905f49ea21","html_url":"https://github.com/kinshuk-code-1729/JDBC-crud","commit_stats":null,"previous_names":["kinshuk-code-1729/jdbc-crud"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kinshuk-code-1729%2FJDBC-crud","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kinshuk-code-1729%2FJDBC-crud/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kinshuk-code-1729%2FJDBC-crud/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kinshuk-code-1729%2FJDBC-crud/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kinshuk-code-1729","download_url":"https://codeload.github.com/kinshuk-code-1729/JDBC-crud/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241361398,"owners_count":19950379,"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":["crud-operation","java","java-database-connectivity","jdbc","mysql-database"],"created_at":"2024-11-12T23:13:41.848Z","updated_at":"2025-11-24T22:03:20.426Z","avatar_url":"https://github.com/kinshuk-code-1729.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JDBC CRUDs\n_**Creating, reading, updating,** and **deleting** data in a database is a common task in many applications, and **JDBC (Java Database Connectivity)** is a **Java API** that allows you to connect to a database and perform these operations._\n\n### Steps of setting up a simple _CRUD (create, read, update, delete)_ operation using _JDBC :_\n\n## 1. Connect to the database :\n_The first step is to establish a connection to the database. You can do this by loading the JDBC driver and creating a connection object._\n```java\ntry { \n\tClass.forName(\"com.mysql.jdbc.Driver\"); \n\tConnection con = DriverManager.getConnection( \n\t\t\"jdbc:mysql://localhost:3306/mydb\", \"username\", \n\t\t\"password\"); \n\tSystem.out.println(\"Connection established.\"); \n} \ncatch (Exception e) { \n\te.printStackTrace(); \n}\n```\n\n## 2. Create a new record :\n_Once you have a connection to the database, you can use the connection object to create a new record in the database. To do this, you will need to use an SQL INSERT statement and execute it using the connection object._\n```java\ntry { \nString sql = \"INSERT INTO table_name (column1, column2, column3) VALUES (?, ?, ?)\"; \nPreparedStatement statement = con.prepareStatement(sql); \nstatement.setString(1, \"value1\"); \nstatement.setString(2, \"value2\"); \nstatement.setInt(3, 123); \nstatement.executeUpdate(); \nSystem.out.println(\"Record created.\"); \n} catch (SQLException e) { \ne.printStackTrace(); \n}\n```\n\n## 3. Read a record :\n_To read a record from the database, you will need to use an SQL SELECT statement and execute it using the connection object. The result of the query will be a ResultSet object that you can use to access the data in the record._\n```java\ntry { \nString sql = \"SELECT column1, column2, column3 FROM table_name WHERE id = ?\"; \nPreparedStatement statement = con.prepareStatement(sql); \nstatement.setInt(1, 1); \nResultSet result = statement.executeQuery(); \nif (result.next()) { \n\tString column1 = result.getString(\"column1\"); \n\tString column2 = result.getString(\"column2\"); \n\tint column3 = result.getInt(\"column3\"); \n\tSystem.out.println(\"Column 1: \" + column1); \n\tSystem.out.println(\"Column 2: \" + column2); \n\tSystem.out.println(\"Column 3: \" + column3); \n} \n} catch (SQLException e) { \ne.printStackTrace(); \n}\n```\n\n## 4. Update a record :\n_To update a record in the database, you will need to use an SQL UPDATE statement and execute it using the connection object._\n```java\ntry { \nString sql = \"UPDATE table_name SET column1 = ?, column2 = ?, column3 = ? WHERE id = ?\"; \nPreparedStatement statement = con.prepareStatement(sql); \nstatement.setString(1, \"new_value1\"); \nstatement.setString(2, \"new_value2\"); \nstatement.setInt(3, 456); \nstatement.setInt(4, 1); \nstatement.executeUpdate(); \nSystem.out.println(\"Record updated.\"); \n} catch (SQLException e) { \ne.printStackTrace(); \n}\n```\n\n## 5. Delete a record :\n_To delete a record from the database, you will need to use an SQL DELETE statement and execute it using the connection object._\n```java\ntry { \nString sql = \"DELETE FROM table_name WHERE id = ?\"; \nPreparedStatement statement = con.prepareStatement(sql); \nstatement.setInt(1, 1); \nstatement.executeUpdate(); \nSystem.out.println(\"Record deleted.\"); \n} catch (SQLException e) { \ne.printStackTrace(); \n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkinshuk-code-1729%2Fjdbc-crud","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkinshuk-code-1729%2Fjdbc-crud","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkinshuk-code-1729%2Fjdbc-crud/lists"}