Advertisement
Guest User

Untitled

a guest
May 29th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.36 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class User {
  4. private int ID_user;
  5. private String username;
  6. private String password;
  7. private String name;
  8. private String birthDay;
  9. private Gender gender;
  10. private int money;
  11. private String address;
  12. public String getUsername() {
  13. return username;
  14. }
  15. public void setUsername(String username) {
  16. this.username = username;
  17. }
  18. public String getPassword() {
  19. return password;
  20. }
  21. public void setPassword(String password) {
  22. this.password = password;
  23. }
  24. public String getName() {
  25. return name;
  26. }
  27. public void setName(String name) {
  28. this.name = name;
  29. }
  30. public String getBirthDay() {
  31. return birthDay;
  32. }
  33. public void setBirthDay(String birthDay) {
  34. this.birthDay = birthDay;
  35. }
  36. public Gender getGender() {
  37. return gender;
  38. }
  39. public void setGender(Gender gender) {
  40. this.gender = gender;
  41. }
  42. public int getMoney() {
  43. return money;
  44. }
  45. public void setMoney(int money) {
  46. this.money = money;
  47. }
  48. public String getAddress() {
  49. return address;
  50. }
  51. public void setAddress(String address) {
  52. this.address = address;
  53. }
  54. public int getID_user() {
  55. return ID_user;
  56. }
  57. public User(int iD_user, String username, String password, String name, String birthDay, Gender gender, int money,
  58. String address) {
  59. super();
  60. ID_user = iD_user;
  61. this.username = username;
  62. this.password = password;
  63. this.name = name;
  64. this.birthDay = birthDay;
  65. this.gender = gender;
  66. this.money = money;
  67. this.address = address;
  68. }
  69.  
  70. public User(String username, String password, String name, String birthDay, Gender gender,
  71. String address) {
  72. super();
  73. this.username = username;
  74. this.password = password;
  75. this.name = name;
  76. this.birthDay = birthDay;
  77. this.gender = gender;
  78. this.money = 1000;
  79. this.address = address;
  80. }
  81.  
  82. public String addToDB()
  83. {
  84. Statement stmt = null;
  85. String valid="failed";
  86. try {
  87. Server.openConnection();
  88. stmt=Server.DBConnection.createStatement();
  89. stmt.executeUpdate("insert into Users "+"values ('"+username+"','"+password+"','"+name+"','"+birthDay+"','"+gender+"',"+money+",'"+address+"')" );
  90. valid="ok";
  91. } catch (SQLException e) {
  92. e.printStackTrace();
  93. }finally {
  94. if (stmt != null) try { stmt.close(); } catch(Exception e) {}
  95. if (Server.DBConnection != null) try { Server.closeConnection(); } catch(Exception e) {}
  96. }
  97. return valid;
  98. }
  99.  
  100. public static void deleteUser(int ID_user)
  101. {
  102. Statement stmt = null;
  103. try {
  104. Server.openConnection();
  105. stmt=Server.DBConnection.createStatement();
  106. stmt.executeUpdate("delete from Users where ID_user="+ID_user);
  107. } catch (SQLException e) {
  108. e.printStackTrace();
  109. }finally {
  110. if (stmt != null) try { stmt.close(); } catch(Exception e) {}
  111. if (Server.DBConnection != null) try { Server.closeConnection(); } catch(Exception e) {}
  112. }
  113. }
  114.  
  115. public static String checkUser(String uname, String passw)
  116. {
  117. String row="User;;";
  118. ResultSet rs=null;
  119. Statement stmt = null;
  120. try {
  121. Server.openConnection();
  122. stmt=Server.DBConnection.createStatement();
  123. rs=stmt.executeQuery("select * from Users where username= '"+uname+"' and password= '"+passw+"' ");
  124. if(rs.next())
  125. 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)+";;";
  126. //row=row+"&";
  127. } catch (SQLException e) {
  128. e.printStackTrace();
  129. }finally {
  130. if (stmt != null) try { stmt.close(); } catch(Exception e) {}
  131. if (Server.DBConnection != null) try { Server.closeConnection(); } catch(Exception e) {}
  132. }
  133.  
  134. return row;
  135. }
  136. }
  137.  
  138. ----------------------------------------------------------------------
  139.  
  140. import java.sql.*;
  141. public class Order {
  142. private int ID_order;
  143. private int ID_product;
  144. private int ID_user;
  145. private int quantity;
  146.  
  147. public int getID_order() {
  148. return ID_order;
  149. }
  150. public int getID_product() {
  151. return ID_product;
  152. }
  153. public void setID_product(int iD_product) {
  154. ID_product = iD_product;
  155. }
  156. public int getID_user() {
  157. return ID_user;
  158. }
  159. public void setID_user(int iD_user) {
  160. ID_user = iD_user;
  161. }
  162.  
  163. public Order(int iD_order, int iD_product, int quantity,int iD_user) {
  164. super();
  165. ID_order = iD_order;
  166. ID_product = iD_product;
  167. this.quantity=quantity;
  168. ID_user = iD_user;
  169. }
  170.  
  171. public Order(int iD_product,int quantity, int iD_user) {
  172. super();
  173. //ID_order = iD_order;
  174. ID_product = iD_product;
  175. this.quantity=quantity;
  176. ID_user = iD_user;
  177. }
  178.  
  179. public void addToDB()
  180. {
  181. Statement stmt = null;
  182. try {
  183. Server.openConnection();
  184. stmt=Server.DBConnection.createStatement();
  185. stmt.executeUpdate("insert into Order "+"values ("+ID_product+","+quantity+","+ID_user+")" );
  186. } catch (SQLException e) {
  187. e.printStackTrace();
  188. }finally {
  189. if (stmt != null) try { stmt.close(); } catch(Exception e) {}
  190. if (Server.DBConnection != null) try { Server.closeConnection(); } catch(Exception e) {}
  191. }
  192. }
  193.  
  194. public static void deleteOrder(int ID_order)
  195. {
  196. Statement stmt = null;
  197. try {
  198. Server.openConnection();
  199. stmt=Server.DBConnection.createStatement();
  200. stmt.executeUpdate("delete from Order where ID_order="+ID_order);
  201. } catch (SQLException e) {
  202. e.printStackTrace();
  203. }finally {
  204. if (stmt != null) try { stmt.close(); } catch(Exception e) {}
  205. if (Server.DBConnection != null) try { Server.closeConnection(); } catch(Exception e) {}
  206. }
  207. }
  208.  
  209. public static String getAllOrder()
  210. {
  211. String row="";
  212. String tabel="Orders;;";
  213. Statement stmt = null;
  214. ResultSet rs = null;
  215. try {
  216. Server.openConnection();
  217. stmt=Server.DBConnection.createStatement();
  218. rs=stmt.executeQuery("select * from Orders");
  219. while (rs.next()) {
  220. row=rs.getString(1)+";;"+rs.getString(2)+";;"+rs.getString(3)+";;";
  221. tabel=tabel+row;
  222. }
  223. //tabel=tabel+"&";
  224. } catch (SQLException e) {
  225. e.printStackTrace();
  226. }finally {
  227. if (rs != null) try { rs.close(); } catch(Exception e) {}
  228. if (stmt != null) try { stmt.close(); } catch(Exception e) {}
  229. if (Server.DBConnection != null) try { Server.closeConnection(); } catch(Exception e) {}
  230. }
  231.  
  232. return tabel;
  233. }
  234.  
  235. }
  236.  
  237.  
  238. -------------------------------------------------------------------------
  239.  
  240. import java.sql.*;
  241.  
  242. public class Product {
  243. private int ID_product;
  244. private ProductType pType;
  245. private String name;
  246. private String specification;
  247. private int price;
  248. private int quantity;
  249.  
  250. public Product(int iD_product, ProductType pType, String name, String specification, int price, int quantity) {
  251. super();
  252. ID_product = iD_product;
  253. this.pType = pType;
  254. this.name = name;
  255. this.specification = specification;
  256. this.price = price;
  257. this.quantity = quantity;
  258. }
  259.  
  260.  
  261.  
  262. public Product(ProductType pType, String name, String specification, int price, int quantity) {
  263. super();
  264. this.pType = pType;
  265. this.name = name;
  266. this.specification = specification;
  267. this.price = price;
  268. this.quantity = quantity;
  269. }
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276. public ProductType getpType() {
  277. return pType;
  278. }
  279.  
  280. public void setpType(ProductType pType) {
  281. this.pType = pType;
  282. }
  283.  
  284. public String getName() {
  285. return name;
  286. }
  287.  
  288. public void setName(String name) {
  289. this.name = name;
  290. }
  291.  
  292. public String getSpecification() {
  293. return specification;
  294. }
  295.  
  296. public void setSpecification(String specification) {
  297. this.specification = specification;
  298. }
  299.  
  300. public int getPrice() {
  301. return price;
  302. }
  303.  
  304. public void setPrice(int price) {
  305. this.price = price;
  306. }
  307.  
  308. public int getQuantity() {
  309. return quantity;
  310. }
  311.  
  312. public void setQuantity(int quantity) {
  313. this.quantity = quantity;
  314. }
  315.  
  316. public int getID_product() {
  317. return ID_product;
  318. }
  319.  
  320. public void addToDB()
  321. {
  322. Statement stmt = null;
  323. try {
  324. Server.openConnection();
  325. stmt=Server.DBConnection.createStatement();
  326. stmt.executeUpdate("insert into Product "+"values ('"+pType+"','"+name+"','"+specification+"',"+price+","+quantity+")" );
  327. } catch (SQLException e) {
  328. e.printStackTrace();
  329. }finally {
  330. if (stmt != null) try { stmt.close(); } catch(Exception e) {}
  331. if (Server.DBConnection != null) try { Server.closeConnection(); } catch(Exception e) {}
  332. }
  333. }
  334.  
  335. public static void deleteProduct(int ID_product)
  336. {
  337. Statement stmt = null;
  338. try {
  339. Server.openConnection();
  340. stmt=Server.DBConnection.createStatement();
  341. stmt.executeUpdate("delete from Product where ID_product="+ID_product);
  342. } catch (SQLException e) {
  343. e.printStackTrace();
  344. }finally {
  345. if (stmt != null) try { stmt.close(); } catch(Exception e) {}
  346. if (Server.DBConnection != null) try { Server.closeConnection(); } catch(Exception e) {}
  347. }
  348. }
  349.  
  350. public static String getProductsByType(ProductType pt)
  351. {
  352. String row="";
  353. String tabel="Products;;";
  354. Statement stmt = null;
  355. ResultSet rs = null;
  356. try {
  357. Server.openConnection();
  358. stmt=Server.DBConnection.createStatement();
  359. rs=stmt.executeQuery("select * from Product where type="+"'"+pt+"'");
  360. while (rs.next()) {
  361. row=rs.getString(1)+";;"+rs.getString(2)+";;"+rs.getString(3)+";;"+rs.getString(4)+";;"+rs.getString(5)+";;"+rs.getString(6)+";;";
  362. tabel=tabel+row;
  363. }
  364. //tabel=tabel+"&";
  365. } catch (SQLException e) {
  366. e.printStackTrace();
  367. }finally {
  368. if (rs != null) try { rs.close(); } catch(Exception e) {}
  369. if (stmt != null) try { stmt.close(); } catch(Exception e) {}
  370. if (Server.DBConnection != null) try { Server.closeConnection(); } catch(Exception e) {}
  371. }
  372.  
  373. return tabel;
  374. }
  375.  
  376. public static String getAllProducts()
  377. {
  378. String row="";
  379. String tabel="Products;;";
  380. Statement stmt = null;
  381. ResultSet rs = null;
  382. try {
  383. Server.openConnection();
  384. stmt=Server.DBConnection.createStatement();
  385. rs=stmt.executeQuery("select * from Product");
  386. while (rs.next()) {
  387. row=rs.getString(1)+";;"+rs.getString(2)+";;"+rs.getString(3)+";;"+rs.getString(4)+";;"+rs.getString(5)+";;"+rs.getString(6)+";;";
  388. tabel=tabel+row;
  389. }
  390. //tabel=tabel+"&";
  391. } catch (SQLException e) {
  392. e.printStackTrace();
  393. }finally {
  394. if (rs != null) try { rs.close(); } catch(Exception e) {}
  395. if (stmt != null) try { stmt.close(); } catch(Exception e) {}
  396. if (Server.DBConnection != null) try { Server.closeConnection(); } catch(Exception e) {}
  397. }
  398.  
  399. return tabel;
  400. }
  401. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement