Program to update record into a table with Mysql.

Here, we have a basic program example to update the data in the existing table using Mysql in Python and Java lannguage.

Code to update data in Python

import mysql.connector
con = mysql.connector.connect(host="localhost", user="root", passwd="root", database="coder")
cur = con.cursor()
#accepting record to be modify
bookname=input("Enter the Book Name")
author=input("New Author to be Modify")
#update query, to modify data
cur.execute("update Book set author='{}' where bookname='{}'".format(author , bookname))
print("Record Updated")

Code to update data in Java

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class UpdateTable {
   public static void main(String[] args) {
      Connection con = null;
      PreparedStatement ps = null;
      try {
         con = DriverManager.getConnection("jdbc :mysql ://localhost :3306/TestDb" +
         "useSSL=false", "root", "vsit@123");
         String query = "update DemoTable set FirstName=? where Id=? ";
         ps = con.prepareStatement(query);
         ps.setString(1, "Neha");
         ps.setInt(2, 13);
         System.out.println("Record is updated successfully......");
         } catch (Exception e) {