Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- import java.sql.*;
- import java.util.*;
- /**
- *
- * @author Anders
- */
- public class importDatabase {
- //six variables of both int and String to store random values from database
- private int Ia;
- private int Ib;
- private int Ic;
- private int Id;
- private int Ie;
- private int If;
- private String Sa;
- private String Sb;
- private String Sc;
- private String Sd;
- private String Se;
- private String Sf;
- public importDatabase()
- {
- }
- public void getValues(ArrayList<Project> project, ArrayList<Resource> resource, ArrayList<Customer> customer)
- {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- String connectionUrl = "jdbc:mysql://mysql.johannahartman.com/d0007n?" +
- "user=d0007n&password=qe3R3P";
- Connection con = DriverManager.getConnection(connectionUrl);
- Statement stmt = null;
- ResultSet rs = null;
- //SQL query command
- String SQL1 = "SELECT * FROM Projekt";
- String SQL2 = "SELECT * FROM Resurser";
- String SQL3 = "SELECT * FROM Kund";
- //getting values from table Projekt
- stmt = con.createStatement();
- rs = stmt.executeQuery(SQL1);
- while (rs.next()) {
- Ia = rs.getInt("projektId");
- Sa = rs.getString("projektNamn");
- Ib = rs.getInt("kundId");
- Sb = rs.getString("startDatum");
- Sc = rs.getString("slutdatum");
- Ic = rs.getInt("projektledare");
- Sd = rs.getString("projektStatus");
- Se = rs.getString("beskrivning");
- Id = rs.getInt("kostnad");
- Ie = rs.getInt("tid");
- }
- //getting values from table Resurser
- rs = stmt.executeQuery(SQL2);
- while (rs.next()) {
- Ia = rs.getInt("personNummer");
- Sa = rs.getString("namn");
- Sb = rs.getString("losen");
- }
- //getting values from table Kund
- rs = stmt.executeQuery(SQL3);
- while (rs.next()) {
- Ia = rs.getInt("kundId");
- Sa = rs.getString("kundnamn");
- Ib = rs.getInt("orgNr");
- Sb = rs.getString("adress");
- Sc = rs.getString("postnummer");
- Sd = rs.getString("postort");
- Se = rs.getString("telefonnummer");
- Sf = rs.getString("faxnummer");
- Customer newCustomer = new Customer(int Ia, String Sa, int Ib, String Sb, String Sc, String Sd, String Se, String Sf);
- }
- } catch (SQLException e) {
- System.out.println("SQL Exception: "+ e.toString());
- } catch (ClassNotFoundException cE) {
- System.out.println("Class Not Found Exception: "+ cE.toString());
- }
- }
- }
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- import java.util.*;
- /**
- *
- * @author Anders
- */
- public abstract class Person
- {
- int id;
- String socSecNo;
- String name;
- String adress;
- String city;
- String postNo;
- String roel;
- String phoneNo;
- String faxNo;
- public Person()
- {
- }
- public Person(String socSecNo, String name, String adress, String postNo, String city)
- {
- this.socSecNo = socSecNo;
- this.socSecNo = socSecNo;
- this.adress = adress;
- this.city = city;
- this.postNo = postNo;
- }
- public void setSocSecNo(String socSecNo)
- {
- this.socSecNo = socSecNo;
- }
- public void setName(String name)
- {
- this.name = name;
- }
- public void setAdress(String adress, String city, String postNo)
- {
- this.adress = adress;
- this.city = city;
- this.postNo = postNo;
- }
- public void setPhoneNo(String phoneNo)
- {
- this.phoneNo = phoneNo;
- }
- public void setRoel(String roel)
- {
- this.roel = roel;
- }
- public String getName()
- {
- return name;
- }
- public String getSocSecNo()
- {
- return socSecNo;
- }
- public String getStreetAdress()
- {
- return adress;
- }
- public String getCity()
- {
- return city;
- }
- public String getPostNo()
- {
- return postNo;
- }
- public void print()
- {
- System.out.println(socSecNo);
- }
- }
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- import java.util.*;
- /**
- *
- * @author Anders
- */
- public class Customer extends Person {
- private int orgNo;
- public Customer(int id, String name, int orgNo, String adress, String postNo, String city, String phoneNo, String faxNo)
- {
- this.id = id;
- this.name = name;
- this.orgNo = orgNo;
- this.adress = adress;
- this.city = city;
- this.postNo = postNo;
- this.phoneNo = phoneNo;
- this.faxNo = faxNo;
- }
- public Customer()
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement