JAVA_PRACTICAL20
JAVA_PRACTICAL20
Output:
Before After
Exercise:
Q.1)Devlop a program to update name of student from jack to john.
Code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class Pr20Ex1
{
public static void main(String [] args)
{
try
{
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/vrd","root","root");
PreparedStatement st = con
.prepareStatement("update student3 set name='John' where name='Jack'");
st.executeUpdate();
System.out.println("record updated");
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
Output:
Before After
Q.2)Develop a program to delete all the records from a product whose “price is
greator than 5000”and ID is ”P1234”.
Code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class Pr20Ex2
{
public static void main(String [] args)
{
try
{
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/
vrd","root","root");
PreparedStatement st = con
.prepareStatement("delete from products where Price>=5000 and ID='P1234'");
st.executeUpdate();
System.out.println("Product deleted");
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
Output:
Before After