-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewAccidentDetails.jsp
More file actions
85 lines (71 loc) · 2.92 KB
/
newAccidentDetails.jsp
File metadata and controls
85 lines (71 loc) · 2.92 KB
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
77
78
79
80
81
82
83
84
85
<%-- <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<!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>
<%
try {
//Create a connection string
//String url = "jdbc:mysql://your_VM:3306/your_db";
String url = "jdbc:mysql://localhost:3306/BarBeerDrinker";
//Load JDBC driver - the interface standardizing the connection procedure. Look at WEB-INF\lib for a mysql connector jar file, otherwise it fails.
Class.forName("com.mysql.jdbc.Driver");
//Create a connection to your DB
//Connection con = DriverManager.getConnection(url, "csuser", "your_pwd");
Connection con = DriverManager.getConnection(url, "root", "wancar");
//Create a SQL statement
Statement stmt = con.createStatement();
//Parse out the information from the newBeer.jsp
String newCar = request.getParameter("car");
String newYear = request.getParameter("model");
String addr = request.getParameter("addr");
String city = request.getParameter("city");
String phone = request.getParameter("phone");
String license = request.getParameter("license");
String manf = request.getParameter("manufacturer");
int uCar = Integer.parseInt(request.getParameter("ucar"));
int uInfo = Integer.parseInt(request.getParameter("uinfo"));
if (uBar>0)
{
//make an update SQL query
String insert1 = "UPDATE cars SET license = ?, addr = ?, city = ?, model = ?" +
"WHERE name = ?";
//make a statement object that will execute the query
PreparedStatement ps = con.prepareStatement(insert1);
//add query parameters to the statement object
ps.setString(1, license);
ps.setString(2, addr);
ps.setString(3, city);
ps.setString(4, phone);
ps.setString(5, newCar);
//run the query against the database
ps.executeUpdate();
}
if (uCar>0)
{
//make an update SQL query
String insert = "UPDATE Cars SET model = ?" +
"WHERE name = ?";
//make a statement object that will execute the query
PreparedStatement ps = con.prepareStatement(insert);
//add query parameters to the statement object
ps.setString(1, manf);
ps.setString(2, newCar);
//run the query against the database
ps.executeUpdate();
}
//close the connection
con.close();
//notify the user that the update succeeded.
out.print("Update succeeded");
} catch (Exception ex) {
}
%>
</body>
</html> --%>