Advertisement
Guest User

ky2yc

a guest
Feb 6th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include "kz9yc.h"
  5.  
  6. namespace jsf2demo
  7. {
  8.  
  9. AddressRegistrationJSFBean::AddressRegistrationJSFBean()
  10. {
  11. initializeJdbc();
  12. }
  13.  
  14. std::wstring AddressRegistrationJSFBean::getLastName()
  15. {
  16. return lastName;
  17. }
  18.  
  19. void AddressRegistrationJSFBean::setLastName(const std::wstring &lastName)
  20. {
  21. this->lastName = lastName;
  22. }
  23.  
  24. std::wstring AddressRegistrationJSFBean::getFirstName()
  25. {
  26. return firstName;
  27. }
  28.  
  29. void AddressRegistrationJSFBean::setFirstName(const std::wstring &firstName)
  30. {
  31. this->firstName = firstName;
  32. }
  33.  
  34. std::wstring AddressRegistrationJSFBean::getMi()
  35. {
  36. return mi;
  37. }
  38.  
  39. void AddressRegistrationJSFBean::setMi(const std::wstring &mi)
  40. {
  41. this->mi = mi;
  42. }
  43.  
  44. std::wstring AddressRegistrationJSFBean::getTelephone()
  45. {
  46. return telephone;
  47. }
  48.  
  49. void AddressRegistrationJSFBean::setTelephone(const std::wstring &telephone)
  50. {
  51. this->telephone = telephone;
  52. }
  53.  
  54. std::wstring AddressRegistrationJSFBean::getEmail()
  55. {
  56. return email;
  57. }
  58.  
  59. void AddressRegistrationJSFBean::setEmail(const std::wstring &email)
  60. {
  61. this->email = email;
  62. }
  63.  
  64. std::wstring AddressRegistrationJSFBean::getStreet()
  65. {
  66. return street;
  67. }
  68.  
  69. void AddressRegistrationJSFBean::setStreet(const std::wstring &street)
  70. {
  71. this->street = street;
  72. }
  73.  
  74. std::wstring AddressRegistrationJSFBean::getCity()
  75. {
  76. return city;
  77. }
  78.  
  79. void AddressRegistrationJSFBean::setCity(const std::wstring &city)
  80. {
  81. this->city = city;
  82. }
  83.  
  84. std::wstring AddressRegistrationJSFBean::getState()
  85. {
  86. return state;
  87. }
  88.  
  89. void AddressRegistrationJSFBean::setState(const std::wstring &state)
  90. {
  91. this->state = state;
  92. }
  93.  
  94. std::wstring AddressRegistrationJSFBean::getZip()
  95. {
  96. return zip;
  97. }
  98.  
  99. void AddressRegistrationJSFBean::setZip(const std::wstring &zip)
  100. {
  101. this->zip = zip;
  102. }
  103.  
  104. bool AddressRegistrationJSFBean::isRquiredFieldsFilled()
  105. {
  106. return !(lastName == L"" || firstName == L"" || StringHelper::trim(lastName)->length() == 0 || StringHelper::trim(firstName)->length() == 0);
  107. }
  108.  
  109. std::wstring AddressRegistrationJSFBean::processSubmit()
  110. {
  111. if (isRquiredFieldsFilled())
  112. {
  113. return L"ConfirmAddress";
  114. }
  115. else
  116. {
  117. return L"";
  118. }
  119. }
  120.  
  121. std::wstring AddressRegistrationJSFBean::getRequiredFields()
  122. {
  123. if (isRquiredFieldsFilled())
  124. {
  125. return L"";
  126. }
  127. else
  128. {
  129. return L"Last Name and First Name are required";
  130. }
  131. }
  132.  
  133. std::wstring AddressRegistrationJSFBean::getInput()
  134. {
  135. return std::wstring(L"<p style=\"color:red\">You entered <br />")
  136. + L"Last Name: " + lastName + L"<br />"
  137. + L"First Name: " + firstName + L"<br />"
  138. + L"MI: " + mi + L"<br />"
  139. + L"Telephone: " + telephone + L"<br />"
  140. + L"Email: " + email + L"<br />"
  141. + L"Street: " + street + L"<br />"
  142. + L"City: " + city + L"<br />"
  143. + L"Street: " + street + L"<br />"
  144. + L"City: " + city + L"<br />"
  145. + L"State: " + state + L"<br />"
  146. + L"Zip: " + zip + L"</p>";
  147. }
  148.  
  149. void AddressRegistrationJSFBean::initializeJdbc()
  150. {
  151. try
  152. {
  153. // Explicitly load a MySQL driver
  154. std::type_info::forName(L"com.mysql.jdbc.Driver");
  155. std::wcout << L"Driver loaded" << std::endl;
  156.  
  157. // Establish a connection
  158. Connection *conn = DriverManager::getConnection(L"jdbc:mysql://localhost/javabook", L"scott", L"tiger");
  159.  
  160. // Create a Statement
  161. pstmt = conn->prepareStatement(std::wstring(L"insert into Address (lastName,") + L" firstName, mi, telephone, email, street, city, " + L"state, zip) values (?, ?, ?, ?, ?, ?, ?, ?, ?)");
  162. }
  163. catch (const std::exception &ex)
  164. {
  165. std::wcout << ex << std::endl;
  166. }
  167. }
  168.  
  169. std::wstring AddressRegistrationJSFBean::storeStudent()
  170. {
  171. try
  172. {
  173. pstmt->setString(1, lastName);
  174. pstmt->setString(2, firstName);
  175. pstmt->setString(3, mi);
  176. pstmt->setString(4, telephone);
  177. pstmt->setString(5, email);
  178. pstmt->setString(6, street);
  179. pstmt->setString(7, city);
  180. pstmt->setString(8, state);
  181. pstmt->setString(9, zip);
  182. pstmt->executeUpdate();
  183. status = firstName + L" " + lastName + L" is now registered in the database.";
  184. }
  185. catch (const std::exception &ex)
  186. {
  187. status = ex.what();
  188. }
  189.  
  190. return L"AddressStoredStatus";
  191. }
  192.  
  193. std::wstring AddressRegistrationJSFBean::getStatus()
  194. {
  195. return status;
  196. }
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement