-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetTripDetailsServlet.java
61 lines (49 loc) · 2.17 KB
/
GetTripDetailsServlet.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class GetTripDetailsServlet extends HttpServlet {
// JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL="jdbc:mysql://localhost:3306/TIMS";
// Database credentials
static final String USER = "root";
static final String PASS = "Subhi@123";
public void doGet(HttpServletRequest request, HttpServletResponse response){
try{
HttpSession session = request.getSession(false);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String uid = (String)session.getAttribute("uid");
String tid = (String)request.getParameter("tid");
//out.println("<p>Driver Access Initialising....</p>");
Class.forName(JDBC_DRIVER);
//out.println("<p>Driver Access Succesful....</p>");
Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
//out.println("<p>Database Connection Successful....</p>");
Statement stmt = conn.createStatement();
String sql = "SELECT * FROM trips WHERE trip_id='"+tid+"'";
ResultSet rs = stmt.executeQuery(sql);
if(rs.next()){
Statement stmt1 = conn.createStatement();
String sql1 = "SELECT * FROM location WHERE loc_id='"+rs.getString("st_place")+"'";
ResultSet rs1 = stmt1.executeQuery(sql1);
if(rs1.next()){
out.println(rs1.getString("city"));
}
Statement stmt2 = conn.createStatement();
String sql2 = "SELECT * FROM location WHERE loc_id='"+rs.getString("dest")+"'";
ResultSet rs2 = stmt1.executeQuery(sql2);
if(rs2.next()){
out.println(rs2.getString("city"));
}
out.println(rs.getString("st_date"));
out.println(rs.getString("end_date"));
}
}
catch(Exception e){
System.out.println(e);
}
}
}