QN045. Write a program to update all record of database table.
1. Objective
To update all record of database table using java program.
2. Theory
In this program, we create statement and execute mysql query to update all record of database table.
3. Source Code
import java.sql.*;
class JDBC45{
public static void main(String[] args){
try{
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/bca_third_2020?serverTimezone=UTC";
String un = "root";
String pw = "";
Connection cn = DriverManager.getConnection(url,un,pw);
updateAll(cn);
}catch(Exception e){
System.out.println(e);
}
}
private static void updateAll(Connection cn) throws SQLException {
Statement stat = cn.createStatement(); // statment create
String query = "update student set course = 'BCA'";
stat.executeUpdate(query); // execute query
System.out.println("Record updated!");
}
}
4. Output
Record updated!
5. Conclusion
In this way, I would like to conclude that by executing mysql query we can update all column at once by using this program.