-
Notifications
You must be signed in to change notification settings - Fork 0
/
InsertItineraryServlet.java
76 lines (59 loc) · 2.47 KB
/
InsertItineraryServlet.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.sql.Date;
import java.text.SimpleDateFormat;
public class InsertItineraryServlet 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{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String tid = (String)request.getParameter("tid");
String ts = (String)request.getParameter("ts");
String dov = request.getParameter("dov");
String st_time = request.getParameter("st_time");
String duration = request.getParameter("duration");
//java.util.Date date = new SimpleDateFormat("dd-mm-yyyy").parse(st_);
//java.sql.Date sqlStartDate = new java.sql.Date(date.getTime());
out.println("==>"+tid+" "+ts+" "+ dov+ " "+ st_time);
Class.forName(JDBC_DRIVER);
Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
Statement stmt = conn.createStatement();
String sql = "SELECT * FROM itineraries WHERE trip_id = '"+tid+"'";
ResultSet rs = stmt.executeQuery(sql);
//out.println("--"+rs.next());//+rs.getString("trip_id"));
int i = 1;
while(rs.next()){
//out.println("g--:"+rs.getString("it_id"));
//out.println("p:"+i);
i = Integer.parseInt(rs.getString("it_id"));
out.println(i);
i+=1;
}
//i=i+1;
out.println(i);
PreparedStatement st = conn.prepareStatement("INSERT INTO itineraries VALUES(?, ?, ?, ?, ?, ?)");
st.setString(1, tid);
st.setString(2, String.valueOf(i));
st.setString(3, ts);
st.setString(4, dov);
st.setString(5, st_time);
st.setString(6, duration);
//st.setString(3, role);
st.executeUpdate();
out.println("successful");
//conn.close();*/
}
catch(Exception e){
System.out.println(e);
}
}
}