Advertisement
Guest User

Untitled

a guest
Sep 16th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.31 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package diaryclasses;
  6.  
  7. import java.sql.Connection;
  8. import java.sql.DriverManager;
  9. import java.sql.Statement;
  10. import java.util.Date;
  11.  
  12. /**
  13.  *
  14.  * @author Satik
  15.  */
  16. public class DiaryRecord {
  17.    
  18.     private int id;
  19.     private String caption;
  20.     private String description;
  21.     private Date started;
  22.     private Date finished;
  23.     private int iduser;
  24.  
  25.     public DiaryRecord(int id, String caption, String description, Date started, Date finished, int iduser) {
  26.         this.id = id;
  27.         this.caption = caption;
  28.         this.description = description;
  29.         this.started = started;
  30.         this.finished = finished;
  31.         this.iduser = iduser;
  32.     }
  33.  
  34.     public String getCaption() {
  35.         return caption;
  36.     }
  37.  
  38.     public String getDescription() {
  39.         return description;
  40.     }
  41.  
  42.     public Date getFinished() {
  43.         return finished;
  44.     }
  45.  
  46.     public int getId() {
  47.         return id;
  48.     }
  49.  
  50.     public int getIduser() {
  51.         return iduser;
  52.     }
  53.  
  54.     public Date getStarted() {
  55.         return started;
  56.     }
  57.  
  58.     public void setCaption(String caption) {
  59.         this.caption = caption;
  60.         try
  61.         {
  62.             Statement stmt;
  63.             Class.forName("com.mysql.jdbc.Driver");
  64.             String url = "jdbc:mysql://localhost:3306/mysql";
  65.             Connection con = DriverManager.getConnection(url,"root", "");
  66.            
  67.             System.out.println("URL: " + url); // debug
  68.             System.out.println("Connection: " + con);
  69.            
  70.             stmt = con.createStatement();
  71.            
  72.             stmt.executeUpdate("UPDATE user SET caption = '"+caption+"' WHERE id='"+this.id+"'");
  73.            
  74.             con.close();
  75.          }
  76.          catch( Exception e )
  77.          {
  78.              System.out.println(e.getStackTrace()); // chyba
  79.          }
  80.     }
  81.  
  82.     public void setDescription(String description) {
  83.         this.description = description;
  84.         try
  85.         {
  86.             Statement stmt;
  87.             Class.forName("com.mysql.jdbc.Driver");
  88.             String url = "jdbc:mysql://localhost:3306/mysql";
  89.             Connection con = DriverManager.getConnection(url,"root", "");
  90.            
  91.             System.out.println("URL: " + url); // debug
  92.             System.out.println("Connection: " + con);
  93.            
  94.             stmt = con.createStatement();
  95.            
  96.             stmt.executeUpdate("UPDATE user SET description = '"+description+"' WHERE id='"+this.id+"'");
  97.            
  98.             con.close();
  99.          }
  100.          catch( Exception e )
  101.          {
  102.              System.out.println(e.getStackTrace()); // chyba
  103.          }
  104.     }
  105.  
  106.     public void setFinished(Date finished) {
  107.         this.finished = finished;
  108.         try
  109.         {
  110.             Statement stmt;
  111.             Class.forName("com.mysql.jdbc.Driver");
  112.             String url = "jdbc:mysql://localhost:3306/mysql";
  113.             Connection con = DriverManager.getConnection(url,"root", "");
  114.            
  115.             System.out.println("URL: " + url); // debug
  116.             System.out.println("Connection: " + con);
  117.            
  118.             stmt = con.createStatement();
  119.            
  120.             stmt.executeUpdate("UPDATE user SET finished = '"+finished+"' WHERE id='"+this.id+"'");
  121.            
  122.             con.close();
  123.          }
  124.          catch( Exception e )
  125.          {
  126.              System.out.println(e.getStackTrace()); // chyba
  127.          }
  128.     }
  129.  
  130.     public void setStarted(Date started) {
  131.         this.started = started;
  132.         try
  133.         {
  134.             Statement stmt;
  135.             Class.forName("com.mysql.jdbc.Driver");
  136.             String url = "jdbc:mysql://localhost:3306/mysql";
  137.             Connection con = DriverManager.getConnection(url,"root", "");
  138.            
  139.             System.out.println("URL: " + url); // debug
  140.             System.out.println("Connection: " + con);
  141.            
  142.             stmt = con.createStatement();
  143.            
  144.             stmt.executeUpdate("UPDATE user SET started = '"+started+"' WHERE id='"+this.id+"'");
  145.            
  146.             con.close();
  147.          }
  148.          catch( Exception e )
  149.          {
  150.              System.out.println(e.getStackTrace()); // chyba
  151.          }
  152.     }
  153.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement