Advertisement
Guest User

Untitled

a guest
May 8th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. public class ConnectionFactory {
  2.  
  3. private static final String DRIVER = "com.mysql.jdbc.Driver";
  4. private static final String URL = "jdbc:mysql://localhost:3306/Pardal";
  5. private static final String USER = "root";
  6. private static final String PASS = "melhor3099__";
  7.  
  8. public static Connection getConnection(){
  9. try {
  10. Class.forName(DRIVER);
  11.  
  12. return (Connection) DriverManager.getConnection(URL, USER, PASS);
  13. } catch (ClassNotFoundException | SQLException ex) {
  14. throw new RuntimeException("ERRO NA CONEXÃO", ex);
  15.  
  16. }
  17. }
  18. public static void closeConnection(Connection con){
  19. if(con != null){
  20. try {
  21. con.close();
  22. } catch (SQLException ex) {
  23. System.err.println("ERRO: "+ex);
  24.  
  25. }
  26. }
  27. }
  28. public static void closeConnection(Connection con, PreparedStatement stnt){
  29. if(stnt != null){
  30. try {
  31. stnt.close();
  32. } catch (SQLException ex) {
  33. System.err.println("ERRO: "+ex);
  34. }
  35. }
  36. closeConnection(con);
  37. }
  38. public static void closeConnection(Connection con, PreparedStatement stnt, ResultSet rs){
  39. if(rs != null){
  40. try {
  41. rs.close();
  42. } catch (SQLException ex) {
  43. System.err.println("ERRO: "+ex);
  44. }
  45. }
  46. closeConnection(con,stnt);
  47. }
  48. }
  49.  
  50.  
  51. public class Categoria {
  52.  
  53. private int id;
  54. private String descrição;
  55.  
  56. public Categoria(){
  57. }
  58.  
  59. public Categoria( String descrição){
  60. this.descrição=descrição;
  61. }
  62.  
  63. public int getId() {
  64. return id;
  65. }
  66.  
  67. public void setId(int id) {
  68. this.id = id;
  69. }
  70.  
  71. public String getDescrição() {
  72. return descrição;
  73. }
  74.  
  75. public void setDescrição(String descrição) {
  76. this.descrição = descrição;
  77. }
  78.  
  79.  
  80.  
  81. }
  82.  
  83. public class Velocidade {
  84.  
  85. private int id;
  86. private String descrição;
  87. private int velocidade;
  88. private Categoria categoria;
  89.  
  90. public Velocidade() {
  91.  
  92. }
  93. public Velocidade(String descrição,int velocidade,Categoria categoria ){
  94. this.descrição=descrição;
  95. this.velocidade=velocidade;
  96. this.categoria=categoria;
  97. }
  98.  
  99. public int getId() {
  100. return id;
  101. }
  102.  
  103. public void setId(int id) {
  104. this.id = id;
  105. }
  106.  
  107. public String getDescrição() {
  108. return descrição;
  109. }
  110.  
  111. public void setDescrição(String descrição) {
  112. this.descrição = descrição;
  113. }
  114.  
  115. public int getVelocidade() {
  116. return velocidade;
  117. }
  118.  
  119. public void setVelocidade(int velocidade) {
  120. this.velocidade = velocidade;
  121. }
  122.  
  123. public Categoria getCategoria() {
  124. return categoria;
  125. }
  126.  
  127. public void setCategoria(Categoria categoria) {
  128. this.categoria = categoria;
  129. }
  130.  
  131.  
  132.  
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement