Advertisement
Guest User

Untitled

a guest
May 24th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.36 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. import java.sql.*;
  6. import java.util.*;
  7. /**
  8.  *
  9.  * @author Anders
  10.  */
  11. public class importDatabase {
  12.     //six variables of both int and String to store random values from database
  13.     private int Ia;
  14.     private int Ib;
  15.     private int Ic;
  16.     private int Id;
  17.     private int Ie;
  18.     private int If;
  19.     private String Sa;
  20.     private String Sb;
  21.     private String Sc;
  22.     private String Sd;
  23.     private String Se;
  24.     private String Sf;
  25.  
  26.     public importDatabase()
  27.     {
  28.        
  29.     }
  30.  
  31.     public void getValues(ArrayList<Project> project, ArrayList<Resource> resource, ArrayList<Customer> customer)
  32.     {
  33.          try {
  34.             Class.forName("com.mysql.jdbc.Driver");
  35.             String connectionUrl = "jdbc:mysql://mysql.johannahartman.com/d0007n?" +
  36.                                    "user=d0007n&password=qe3R3P";
  37.             Connection con = DriverManager.getConnection(connectionUrl);
  38.  
  39.             Statement stmt = null;
  40.             ResultSet rs = null;
  41.             //SQL query command
  42.             String SQL1 = "SELECT * FROM Projekt";
  43.             String SQL2 = "SELECT * FROM Resurser";
  44.             String SQL3 = "SELECT * FROM Kund";
  45.  
  46.             //getting values from table Projekt
  47.             stmt = con.createStatement();
  48.             rs = stmt.executeQuery(SQL1);
  49.             while (rs.next()) {
  50.                 Ia = rs.getInt("projektId");
  51.                 Sa = rs.getString("projektNamn");
  52.                 Ib = rs.getInt("kundId");
  53.                 Sb = rs.getString("startDatum");
  54.                 Sc = rs.getString("slutdatum");
  55.                 Ic = rs.getInt("projektledare");
  56.                 Sd = rs.getString("projektStatus");
  57.                 Se = rs.getString("beskrivning");
  58.                 Id = rs.getInt("kostnad");
  59.                 Ie = rs.getInt("tid");
  60.            
  61.             }
  62.  
  63.             //getting values from table Resurser
  64.             rs = stmt.executeQuery(SQL2);
  65.             while (rs.next()) {
  66.                 Ia = rs.getInt("personNummer");
  67.                 Sa = rs.getString("namn");
  68.                 Sb = rs.getString("losen");
  69.             }
  70.  
  71.             //getting values from table Kund
  72.             rs = stmt.executeQuery(SQL3);
  73.             while (rs.next()) {
  74.                 Ia = rs.getInt("kundId");
  75.                 Sa = rs.getString("kundnamn");
  76.                 Ib = rs.getInt("orgNr");
  77.                 Sb = rs.getString("adress");
  78.                 Sc = rs.getString("postnummer");
  79.                 Sd = rs.getString("postort");
  80.                 Se = rs.getString("telefonnummer");
  81.                 Sf = rs.getString("faxnummer");
  82.                 Customer newCustomer = new Customer(int Ia, String Sa, int Ib, String Sb, String Sc, String Sd, String Se, String Sf);
  83.  
  84.             }
  85.  
  86.  
  87.            
  88.         } catch (SQLException e) {
  89.             System.out.println("SQL Exception: "+ e.toString());
  90.         } catch (ClassNotFoundException cE) {
  91.             System.out.println("Class Not Found Exception: "+ cE.toString());
  92.         }
  93.     }
  94. }
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101. /*
  102.  * To change this template, choose Tools | Templates
  103.  * and open the template in the editor.
  104.  */
  105. import java.util.*;
  106. /**
  107.  *
  108.  * @author Anders
  109.  */
  110. public abstract class Person
  111. {
  112.     int id;
  113.     String socSecNo;
  114.     String name;
  115.     String adress;
  116.     String city;
  117.     String postNo;
  118.     String roel;
  119.     String phoneNo;
  120.     String faxNo;
  121.  
  122.     public Person()
  123.     {
  124.     }
  125.  
  126.     public Person(String socSecNo, String name, String adress, String postNo, String city)
  127.     {
  128.        this.socSecNo = socSecNo;
  129.        this.socSecNo = socSecNo;
  130.        this.adress = adress;
  131.        this.city = city;
  132.        this.postNo = postNo;
  133.     }
  134.  
  135.     public void setSocSecNo(String socSecNo)
  136.     {
  137.         this.socSecNo = socSecNo;
  138.     }
  139.  
  140.     public void setName(String name)
  141.     {
  142.         this.name = name;
  143.     }
  144.  
  145.     public void setAdress(String adress, String city, String postNo)
  146.     {
  147.         this.adress = adress;
  148.         this.city = city;
  149.         this.postNo = postNo;
  150.     }
  151.  
  152.     public void setPhoneNo(String phoneNo)
  153.     {
  154.         this.phoneNo = phoneNo;
  155.     }
  156.  
  157.     public void setRoel(String roel)
  158.     {
  159.         this.roel = roel;
  160.     }
  161.  
  162.     public String getName()
  163.     {
  164.         return name;
  165.     }
  166.  
  167.     public String getSocSecNo()
  168.     {
  169.         return socSecNo;
  170.     }
  171.  
  172.     public String getStreetAdress()
  173.     {
  174.         return adress;
  175.     }
  176.  
  177.     public String getCity()
  178.     {
  179.         return city;
  180.     }
  181.  
  182.     public String getPostNo()
  183.     {
  184.         return postNo;
  185.     }
  186.  
  187.     public void print()
  188.     {
  189.         System.out.println(socSecNo);
  190.     }
  191.  
  192. }
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206. /*
  207.  * To change this template, choose Tools | Templates
  208.  * and open the template in the editor.
  209.  */
  210. import java.util.*;
  211. /**
  212.  *
  213.  * @author Anders
  214.  */
  215. public class Customer extends Person {
  216.  
  217.         private int orgNo;
  218.        
  219.     public Customer(int id, String name, int orgNo, String adress, String postNo, String city, String phoneNo, String faxNo)
  220.     {
  221.        this.id = id;
  222.        this.name = name;
  223.        this.orgNo = orgNo;
  224.        this.adress = adress;
  225.        this.city = city;
  226.        this.postNo = postNo;
  227.        this.phoneNo = phoneNo;
  228.         this.faxNo = faxNo;
  229.     }
  230.  
  231.     public Customer()
  232.     {
  233.        
  234.     }
  235.  
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement