Asked on 28 Jan, 2021
0
531 Views
write a program to update data on following table
Table:student
Column
Name Type
id number
name varchar
age number
lets try setting name = 'adult' if age > 20
import java.sql.* ;
public class UpdateTable{
public static void main(String[] agrs){
Connection connection ;
PreparedStatement ps ;
try(
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/students", "user", "password") ;
ps = connection.prepareStatement("Update student set name = ? where age > 20") ;
ps.setString(1, "aged") ;
){
int updateCount = ps.executeUpdate() ;
System.out.println(updateCount + " rows updated") ;
}catch(Exception e){e.printStackTrace();}
}
}
Add your answer