Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class User {
- private int ID_user;
- private String username;
- private String password;
- private String name;
- private String birthDay;
- private Gender gender;
- private int money;
- private String address;
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getBirthDay() {
- return birthDay;
- }
- public void setBirthDay(String birthDay) {
- this.birthDay = birthDay;
- }
- public Gender getGender() {
- return gender;
- }
- public void setGender(Gender gender) {
- this.gender = gender;
- }
- public int getMoney() {
- return money;
- }
- public void setMoney(int money) {
- this.money = money;
- }
- public String getAddress() {
- return address;
- }
- public void setAddress(String address) {
- this.address = address;
- }
- public int getID_user() {
- return ID_user;
- }
- public User(int iD_user, String username, String password, String name, String birthDay, Gender gender, int money,
- String address) {
- super();
- ID_user = iD_user;
- this.username = username;
- this.password = password;
- this.name = name;
- this.birthDay = birthDay;
- this.gender = gender;
- this.money = money;
- this.address = address;
- }
- public User(String username, String password, String name, String birthDay, Gender gender,
- String address) {
- super();
- this.username = username;
- this.password = password;
- this.name = name;
- this.birthDay = birthDay;
- this.gender = gender;
- this.money = 1000;
- this.address = address;
- }
- public String addToDB()
- {
- Statement stmt = null;
- String valid="failed";
- try {
- Server.openConnection();
- stmt=Server.DBConnection.createStatement();
- stmt.executeUpdate("insert into Users "+"values ('"+username+"','"+password+"','"+name+"','"+birthDay+"','"+gender+"',"+money+",'"+address+"')" );
- valid="ok";
- } catch (SQLException e) {
- e.printStackTrace();
- }finally {
- if (stmt != null) try { stmt.close(); } catch(Exception e) {}
- if (Server.DBConnection != null) try { Server.closeConnection(); } catch(Exception e) {}
- }
- return valid;
- }
- public static void deleteUser(int ID_user)
- {
- Statement stmt = null;
- try {
- Server.openConnection();
- stmt=Server.DBConnection.createStatement();
- stmt.executeUpdate("delete from Users where ID_user="+ID_user);
- } catch (SQLException e) {
- e.printStackTrace();
- }finally {
- if (stmt != null) try { stmt.close(); } catch(Exception e) {}
- if (Server.DBConnection != null) try { Server.closeConnection(); } catch(Exception e) {}
- }
- }
- public static String checkUser(String uname, String passw)
- {
- String row="User;;";
- ResultSet rs=null;
- Statement stmt = null;
- try {
- Server.openConnection();
- stmt=Server.DBConnection.createStatement();
- rs=stmt.executeQuery("select * from Users where username= '"+uname+"' and password= '"+passw+"' ");
- if(rs.next())
- row=row+rs.getString(1)+";;"+rs.getString(2)+";;"+rs.getString(3)+";;"+rs.getString(4)+";;"+rs.getString(5)+";;"+rs.getString(6)+";;"+rs.getString(7)+";;"+rs.getString(8)+";;";
- //row=row+"&";
- } catch (SQLException e) {
- e.printStackTrace();
- }finally {
- if (stmt != null) try { stmt.close(); } catch(Exception e) {}
- if (Server.DBConnection != null) try { Server.closeConnection(); } catch(Exception e) {}
- }
- return row;
- }
- }
- ----------------------------------------------------------------------
- import java.sql.*;
- public class Order {
- private int ID_order;
- private int ID_product;
- private int ID_user;
- private int quantity;
- public int getID_order() {
- return ID_order;
- }
- public int getID_product() {
- return ID_product;
- }
- public void setID_product(int iD_product) {
- ID_product = iD_product;
- }
- public int getID_user() {
- return ID_user;
- }
- public void setID_user(int iD_user) {
- ID_user = iD_user;
- }
- public Order(int iD_order, int iD_product, int quantity,int iD_user) {
- super();
- ID_order = iD_order;
- ID_product = iD_product;
- this.quantity=quantity;
- ID_user = iD_user;
- }
- public Order(int iD_product,int quantity, int iD_user) {
- super();
- //ID_order = iD_order;
- ID_product = iD_product;
- this.quantity=quantity;
- ID_user = iD_user;
- }
- public void addToDB()
- {
- Statement stmt = null;
- try {
- Server.openConnection();
- stmt=Server.DBConnection.createStatement();
- stmt.executeUpdate("insert into Order "+"values ("+ID_product+","+quantity+","+ID_user+")" );
- } catch (SQLException e) {
- e.printStackTrace();
- }finally {
- if (stmt != null) try { stmt.close(); } catch(Exception e) {}
- if (Server.DBConnection != null) try { Server.closeConnection(); } catch(Exception e) {}
- }
- }
- public static void deleteOrder(int ID_order)
- {
- Statement stmt = null;
- try {
- Server.openConnection();
- stmt=Server.DBConnection.createStatement();
- stmt.executeUpdate("delete from Order where ID_order="+ID_order);
- } catch (SQLException e) {
- e.printStackTrace();
- }finally {
- if (stmt != null) try { stmt.close(); } catch(Exception e) {}
- if (Server.DBConnection != null) try { Server.closeConnection(); } catch(Exception e) {}
- }
- }
- public static String getAllOrder()
- {
- String row="";
- String tabel="Orders;;";
- Statement stmt = null;
- ResultSet rs = null;
- try {
- Server.openConnection();
- stmt=Server.DBConnection.createStatement();
- rs=stmt.executeQuery("select * from Orders");
- while (rs.next()) {
- row=rs.getString(1)+";;"+rs.getString(2)+";;"+rs.getString(3)+";;";
- tabel=tabel+row;
- }
- //tabel=tabel+"&";
- } catch (SQLException e) {
- e.printStackTrace();
- }finally {
- if (rs != null) try { rs.close(); } catch(Exception e) {}
- if (stmt != null) try { stmt.close(); } catch(Exception e) {}
- if (Server.DBConnection != null) try { Server.closeConnection(); } catch(Exception e) {}
- }
- return tabel;
- }
- }
- -------------------------------------------------------------------------
- import java.sql.*;
- public class Product {
- private int ID_product;
- private ProductType pType;
- private String name;
- private String specification;
- private int price;
- private int quantity;
- public Product(int iD_product, ProductType pType, String name, String specification, int price, int quantity) {
- super();
- ID_product = iD_product;
- this.pType = pType;
- this.name = name;
- this.specification = specification;
- this.price = price;
- this.quantity = quantity;
- }
- public Product(ProductType pType, String name, String specification, int price, int quantity) {
- super();
- this.pType = pType;
- this.name = name;
- this.specification = specification;
- this.price = price;
- this.quantity = quantity;
- }
- public ProductType getpType() {
- return pType;
- }
- public void setpType(ProductType pType) {
- this.pType = pType;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getSpecification() {
- return specification;
- }
- public void setSpecification(String specification) {
- this.specification = specification;
- }
- public int getPrice() {
- return price;
- }
- public void setPrice(int price) {
- this.price = price;
- }
- public int getQuantity() {
- return quantity;
- }
- public void setQuantity(int quantity) {
- this.quantity = quantity;
- }
- public int getID_product() {
- return ID_product;
- }
- public void addToDB()
- {
- Statement stmt = null;
- try {
- Server.openConnection();
- stmt=Server.DBConnection.createStatement();
- stmt.executeUpdate("insert into Product "+"values ('"+pType+"','"+name+"','"+specification+"',"+price+","+quantity+")" );
- } catch (SQLException e) {
- e.printStackTrace();
- }finally {
- if (stmt != null) try { stmt.close(); } catch(Exception e) {}
- if (Server.DBConnection != null) try { Server.closeConnection(); } catch(Exception e) {}
- }
- }
- public static void deleteProduct(int ID_product)
- {
- Statement stmt = null;
- try {
- Server.openConnection();
- stmt=Server.DBConnection.createStatement();
- stmt.executeUpdate("delete from Product where ID_product="+ID_product);
- } catch (SQLException e) {
- e.printStackTrace();
- }finally {
- if (stmt != null) try { stmt.close(); } catch(Exception e) {}
- if (Server.DBConnection != null) try { Server.closeConnection(); } catch(Exception e) {}
- }
- }
- public static String getProductsByType(ProductType pt)
- {
- String row="";
- String tabel="Products;;";
- Statement stmt = null;
- ResultSet rs = null;
- try {
- Server.openConnection();
- stmt=Server.DBConnection.createStatement();
- rs=stmt.executeQuery("select * from Product where type="+"'"+pt+"'");
- while (rs.next()) {
- row=rs.getString(1)+";;"+rs.getString(2)+";;"+rs.getString(3)+";;"+rs.getString(4)+";;"+rs.getString(5)+";;"+rs.getString(6)+";;";
- tabel=tabel+row;
- }
- //tabel=tabel+"&";
- } catch (SQLException e) {
- e.printStackTrace();
- }finally {
- if (rs != null) try { rs.close(); } catch(Exception e) {}
- if (stmt != null) try { stmt.close(); } catch(Exception e) {}
- if (Server.DBConnection != null) try { Server.closeConnection(); } catch(Exception e) {}
- }
- return tabel;
- }
- public static String getAllProducts()
- {
- String row="";
- String tabel="Products;;";
- Statement stmt = null;
- ResultSet rs = null;
- try {
- Server.openConnection();
- stmt=Server.DBConnection.createStatement();
- rs=stmt.executeQuery("select * from Product");
- while (rs.next()) {
- row=rs.getString(1)+";;"+rs.getString(2)+";;"+rs.getString(3)+";;"+rs.getString(4)+";;"+rs.getString(5)+";;"+rs.getString(6)+";;";
- tabel=tabel+row;
- }
- //tabel=tabel+"&";
- } catch (SQLException e) {
- e.printStackTrace();
- }finally {
- if (rs != null) try { rs.close(); } catch(Exception e) {}
- if (stmt != null) try { stmt.close(); } catch(Exception e) {}
- if (Server.DBConnection != null) try { Server.closeConnection(); } catch(Exception e) {}
- }
- return tabel;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement