Advertisement
Guest User

Untitled

a guest
Nov 16th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. package prova;
  2.  
  3. import java.sql.Connection;
  4. import java.util.Date ;
  5. import java.sql.DriverManager;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9. import java.sql.Timestamp;
  10. import java.text.SimpleDateFormat;
  11. import java.util.Calendar;
  12.  
  13.  
  14. public class DAO {
  15.  
  16. private Connection conn = null;
  17.  
  18. public void criarServico(int codigo_animal, String descricao, double valor) throws ClassNotFoundException, SQLException{
  19. Calendar cal = Calendar.getInstance();
  20. Date dt = cal.getTime();
  21. SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  22. String entrada = sdf.format(dt);
  23. Class.forName("com.mysql.jdbc.Driver");
  24. conn = DriverManager.getConnection("jdbc:mysql://localhost:8889/prova?" + "user=root&password=root&");
  25. Statement statement = conn.createStatement();
  26. statement.executeUpdate("INSERT INTO servico"
  27. + " (codigo_animal,descricao, valor, entrada)"
  28. + "VALUES (" + "'" + codigo_animal + "'" + "," + "'" + descricao + "'" + "," + "'"
  29. + valor+ "'" + ","+ "'" + entrada + "'" + ")");
  30. conn.close();
  31. }
  32.  
  33. public void updateServico(int codigo, String saida) throws ClassNotFoundException, SQLException{
  34. Class.forName("com.mysql.jdbc.Driver");
  35. conn = DriverManager.getConnection("jdbc:mysql://localhost:8889/prova?" + "user=root&password=root&");
  36. Statement statement = conn.createStatement();
  37. statement.executeUpdate("UPDATE servico set saida = "
  38. + "'" + saida + "'" + "WHERE codigo = " + "'" + codigo + "';");
  39. conn.close();
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement