Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
- pageEncoding="ISO-8859-1"%>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
- "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
- <title>Insert title here</title>
- </head>
- <body>
- <form action="mrtservlet" method="post">
- Enter first name: <input type="text" name="fname">
- Enter last name: <input type="text" name="lname">
- Destination: <input type="text" name="dest">
- <input type="submit" value="submit">
- </form>
- </body>
- </html>
- package model;
- public class earnings {
- private int fare;
- private int sno;
- public int getfare(){
- return fare;
- }
- public void setfare(int fare){
- this.fare = fare;
- }
- public int getsno(){
- return sno;
- }
- public void setsno(int sno){
- this.sno = sno;
- }
- }
- package model;
- public class passengers {
- private String fname;
- private String lname;
- private String dest;
- public String getfname(){
- return fname;
- }
- public void setfname(String fname){
- this.fname = fname;
- }
- public String getlname(){
- return lname;
- }
- public void setlname(String lname){
- this.lname = lname;
- }
- public String getdest(){
- return dest;
- }
- public void setdest(String dest){
- this.dest = dest;
- }
- }
- package utilities;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.InputStream;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.util.Properties;
- public class earnings_connection {
- private static Connection connection = null;
- public static Connection getConnection() {
- if (connection != null)
- return connection;
- else {
- try {
- Properties prop = new Properties();
- InputStream=inputStreampassengers_connection.class.getClassLoader().getResourceAsStream("/db.properties0");
- prop.load(inputStream);
- String driver = prop.getProperty("driver");
- String url = prop.getProperty("url");
- String user = prop.getProperty("user");
- String password = prop.getProperty("password");
- Class.forName(driver);
- connection = DriverManager.getConnection(url, user, password);
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return connection;
- }
- }
- }
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.InputStream;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.util.Properties;
- public class passengers_connection {
- private static Connection connection = null;
- public static Connection getConnection() {
- if (connection != null)
- return connection;
- else {
- try {
- Properties prop = new Properties();
- InputStream inputStream = passengers_connection.class.getClassLoader().getResourceAsStream("/db.properties");
- prop.load(inputStream);
- String driver = prop.getProperty("driver");
- String url = prop.getProperty("url");
- String user = prop.getProperty("user");
- String password = prop.getProperty("password");
- Class.forName(driver);
- connection = DriverManager.getConnection(url, user, password);
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return connection;
- }
- }
- }
- package utilities;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import java.util.List;
- import model.earnings;
- public class earnings_dao {
- private Connection connection;
- public earnings_dao(){
- connection = utilities.passengers_connection.getConnection();
- }
- public void insertrip(earnings user) {
- try {
- PreparedStatement preparedStatement = connection
- .prepareStatement("insert into Earnings(Stop No,Fare)"
- + "values (?, ?)");
- preparedStatement.setInt(1, user.getsno());
- preparedStatement.setInt(2, user.getfare());
- preparedStatement.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public List<earnings> getAllUsers() {
- List<earnings> users = new ArrayList<earnings>();
- try {
- Statement statement = connection.createStatement();
- ResultSet rs = statement.executeQuery("select Stop No from Earnings");
- while (rs.next()) {
- earnings user = new earnings();
- user.setsno(rs.getInt("Stop No"));
- users.add(user);}
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return users;
- }
- }
- package utilities;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import model.passengers;
- public class passengers_dao {
- private Connection connection;
- public passengers_dao(){
- connection = utilities.passengers_connection.getConnection();
- }
- public void insertrip(passengers user) {
- try {
- PreparedStatement preparedStatement = connection
- .prepareStatement("insert into Passengers(firstname,lastname,destination)"
- + "values (?, ?, ?)");
- preparedStatement.setString(1, user.getfname());
- preparedStatement.setString(2, user.getlname());
- preparedStatement.setString(3, user.getdest());
- preparedStatement.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement