Advertisement
Guest User

Untitled

a guest
Mar 10th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.72 KB | None | 0 0
  1. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  2. pageEncoding="ISO-8859-1"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  4. "http://www.w3.org/TR/html4/loose.dtd">
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  8. <title>Insert title here</title>
  9. </head>
  10. <body>
  11. <form action="mrtservlet" method="post">
  12. Enter first name: <input type="text" name="fname">
  13. Enter last name: <input type="text" name="lname">
  14. Destination: <input type="text" name="dest">
  15. <input type="submit" value="submit">
  16. </form>
  17. </body>
  18. </html>
  19.  
  20. package model;
  21.  
  22. public class earnings {
  23. private int fare;
  24. private int sno;
  25.  
  26. public int getfare(){
  27. return fare;
  28. }
  29. public void setfare(int fare){
  30. this.fare = fare;
  31. }
  32. public int getsno(){
  33. return sno;
  34. }
  35. public void setsno(int sno){
  36. this.sno = sno;
  37. }
  38. }
  39.  
  40. package model;
  41.  
  42. public class passengers {
  43. private String fname;
  44. private String lname;
  45. private String dest;
  46.  
  47. public String getfname(){
  48. return fname;
  49. }
  50. public void setfname(String fname){
  51. this.fname = fname;
  52. }
  53. public String getlname(){
  54. return lname;
  55. }
  56. public void setlname(String lname){
  57. this.lname = lname;
  58. }
  59. public String getdest(){
  60. return dest;
  61. }
  62. public void setdest(String dest){
  63. this.dest = dest;
  64. }
  65. }
  66.  
  67. package utilities;
  68.  
  69. import java.io.FileNotFoundException;
  70. import java.io.IOException;
  71. import java.io.InputStream;
  72. import java.sql.Connection;
  73. import java.sql.DriverManager;
  74. import java.sql.SQLException;
  75. import java.util.Properties;
  76.  
  77. public class earnings_connection {
  78.  
  79. private static Connection connection = null;
  80.  
  81. public static Connection getConnection() {
  82. if (connection != null)
  83. return connection;
  84. else {
  85. try {
  86. Properties prop = new Properties();
  87. InputStream=inputStreampassengers_connection.class.getClassLoader().getResourceAsStream("/db.properties0");
  88. prop.load(inputStream);
  89. String driver = prop.getProperty("driver");
  90. String url = prop.getProperty("url");
  91. String user = prop.getProperty("user");
  92. String password = prop.getProperty("password");
  93. Class.forName(driver);
  94. connection = DriverManager.getConnection(url, user, password);
  95. } catch (ClassNotFoundException e) {
  96. e.printStackTrace();
  97. } catch (SQLException e) {
  98. e.printStackTrace();
  99. } catch (FileNotFoundException e) {
  100. e.printStackTrace();
  101. } catch (IOException e) {
  102. e.printStackTrace();
  103. }
  104. return connection;
  105. }
  106. }
  107. }
  108.  
  109. import java.io.FileNotFoundException;
  110. import java.io.IOException;
  111. import java.io.InputStream;
  112. import java.sql.Connection;
  113. import java.sql.DriverManager;
  114. import java.sql.SQLException;
  115. import java.util.Properties;
  116.  
  117. public class passengers_connection {
  118.  
  119. private static Connection connection = null;
  120.  
  121. public static Connection getConnection() {
  122. if (connection != null)
  123. return connection;
  124. else {
  125. try {
  126. Properties prop = new Properties();
  127. InputStream inputStream = passengers_connection.class.getClassLoader().getResourceAsStream("/db.properties");
  128. prop.load(inputStream);
  129. String driver = prop.getProperty("driver");
  130. String url = prop.getProperty("url");
  131. String user = prop.getProperty("user");
  132. String password = prop.getProperty("password");
  133. Class.forName(driver);
  134. connection = DriverManager.getConnection(url, user, password);
  135. } catch (ClassNotFoundException e) {
  136. e.printStackTrace();
  137. } catch (SQLException e) {
  138. e.printStackTrace();
  139. } catch (FileNotFoundException e) {
  140. e.printStackTrace();
  141. } catch (IOException e) {
  142. e.printStackTrace();
  143. }
  144. return connection;
  145. }
  146.  
  147. }
  148. }
  149.  
  150. package utilities;
  151.  
  152. import java.sql.Connection;
  153. import java.sql.PreparedStatement;
  154. import java.sql.ResultSet;
  155. import java.sql.SQLException;
  156. import java.sql.Statement;
  157. import java.util.ArrayList;
  158. import java.util.List;
  159.  
  160. import model.earnings;
  161.  
  162. public class earnings_dao {
  163.  
  164. private Connection connection;
  165.  
  166. public earnings_dao(){
  167. connection = utilities.passengers_connection.getConnection();
  168. }
  169.  
  170. public void insertrip(earnings user) {
  171. try {
  172. PreparedStatement preparedStatement = connection
  173. .prepareStatement("insert into Earnings(Stop No,Fare)"
  174. + "values (?, ?)");
  175. preparedStatement.setInt(1, user.getsno());
  176. preparedStatement.setInt(2, user.getfare());
  177. preparedStatement.executeUpdate();
  178. } catch (SQLException e) {
  179. e.printStackTrace();
  180. }
  181. }
  182.  
  183. public List<earnings> getAllUsers() {
  184. List<earnings> users = new ArrayList<earnings>();
  185. try {
  186. Statement statement = connection.createStatement();
  187. ResultSet rs = statement.executeQuery("select Stop No from Earnings");
  188. while (rs.next()) {
  189. earnings user = new earnings();
  190. user.setsno(rs.getInt("Stop No"));
  191. users.add(user);}
  192. } catch (SQLException e) {
  193. e.printStackTrace();
  194. }
  195. return users;
  196. }
  197. }
  198.  
  199. package utilities;
  200.  
  201. import java.sql.Connection;
  202. import java.sql.PreparedStatement;
  203. import java.sql.SQLException;
  204. import model.passengers;
  205.  
  206.  
  207. public class passengers_dao {
  208.  
  209. private Connection connection;
  210.  
  211. public passengers_dao(){
  212. connection = utilities.passengers_connection.getConnection();
  213. }
  214.  
  215. public void insertrip(passengers user) {
  216. try {
  217. PreparedStatement preparedStatement = connection
  218. .prepareStatement("insert into Passengers(firstname,lastname,destination)"
  219. + "values (?, ?, ?)");
  220. preparedStatement.setString(1, user.getfname());
  221. preparedStatement.setString(2, user.getlname());
  222. preparedStatement.setString(3, user.getdest());
  223. preparedStatement.executeUpdate();
  224. } catch (SQLException e) {
  225. e.printStackTrace();
  226. }
  227.  
  228. }
  229. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement