Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class UpdateExample {
  4. public static void main(String[] args) {
  5. Connection connection = null;
  6. try {
  7. Class.forName("com.mysql.jdbc.Driver");
  8. connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/student", "root", "");
  9. Statement statement = connection.createStatement();
  10. String sql = "UPDATE student_table SET name = 'Nguyen Van B' where student_code='SV2'";
  11. statement.executeUpdate(sql);
  12. System.out.println("DONE!");
  13. } catch (ClassNotFoundException | SQLException e) {
  14. System.err.println(e);
  15. } finally {
  16. if (connection != null)
  17. try {
  18. connection.close();
  19. } catch (SQLException e) {
  20. System.err.println(e);
  21. }
  22. }
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement