-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget.jsp
More file actions
183 lines (145 loc) · 5.6 KB
/
get.jsp
File metadata and controls
183 lines (145 loc) · 5.6 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<%@ 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.*" %>
<%@ page import="java.util.Random,java.sql.Time" %>
<!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>
<%
List<String> list = new ArrayList<String>();
try {
//Create a connection string
//String url = "jdbc:mysql://your_VM:3306/your_db";
String url = "jdbc:mysql://cs336final.cqmmn85plgcy.us-east-1.rds.amazonaws.com:3306/cs336final";
//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, "cs336", "finalproject");
//Create a SQL statement
Statement stmt = con.createStatement();
String car = (String)request.getParameter("`make/model`");
String city =(String)request.getParameter("`city/town`");
String type =(String)request.getParameter("type");
String age =(String)request.getParameter("age");
int atr1=1;
int atr2=1;
if(type.equals("22")){
atr1=12;
}else if(type.equals("17")){
atr1=9;
}else if(type.equals("12")){
atr1=5;
}
if(age.equals("100")){
atr2=240;
}else if(age.equals("80")){
atr2=180;
}else if(age.equals("40")){
atr2=140;
}else if(type.equals("25")){
atr2=125;
}else if(type.equals("20")){
atr2=100;
}else if(type.equals("15")){
atr2=85;
}
Random random = new Random();
int total = atr1*atr2;
total+=17+1;
out.print("Based on our data, your approximate insurance premium would be: $"+total+" per year, ie. $"+(total/12)+" per month");
//close the connection.
con.close();
} catch (Exception e) {
e.printStackTrace();
}
%>
<!-- <script type="text/javascript">
// ref: http://stackoverflow.com/a/1293163/2343
// This will parse a delimited string into an array of
// arrays. The default delimiter is the comma, but this
// can be overriden in the second argument.
function CSVToArray( strData, strDelimiter ){
// Check to see if the delimiter is defined. If not,
// then default to comma.
strDelimiter = (strDelimiter || ",");
// Create a regular expression to parse the CSV values.
var objPattern = new RegExp(
(
// Delimiters.
"(\\" + strDelimiter + "|\\r?\\n|\\r|^)" +
// Quoted fields.
"(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" +
// Standard fields.
"([^\"\\" + strDelimiter + "\\r\\n]*))"
),
"gi"
);
// Create an array to hold our data. Give the array
// a default empty first row.
var arrData = [[]];
// Create an array to hold our individual pattern
// matching groups.
var arrMatches = null;
// Keep looping over the regular expression matches
// until we can no longer find a match.
while (arrMatches = objPattern.exec( strData )){
// Get the delimiter that was found.
var strMatchedDelimiter = arrMatches[ 1 ];
// Check to see if the given delimiter has a length
// (is not the start of string) and if it matches
// field delimiter. If id does not, then we know
// that this delimiter is a row delimiter.
if (
strMatchedDelimiter.length &&
strMatchedDelimiter !== strDelimiter
){
// Since we have reached a new row of data,
// add an empty row to our data array.
arrData.push( [] );
}
var strMatchedValue;
// Now that we have our delimiter out of the way,
// let's check to see which kind of value we
// captured (quoted or unquoted).
if (arrMatches[ 2 ]){
// We found a quoted value. When we capture
// this value, unescape any double quotes.
strMatchedValue = arrMatches[ 2 ].replace(
new RegExp( "\"\"", "g" ),
"\""
);
} else {
// We found a non-quoted value.
strMatchedValue = arrMatches[ 3 ];
}
// Now that we have our value string, let's add
// it to the data array.
arrData[ arrData.length - 1 ].push( strMatchedValue );
}
// Return the parsed data.
return( arrData );
}
</script>
(function() {
var csv_path = "data/sample.csv",
var renderCSVDropdown = function(csv) {
var dropdown = $('select#my-dropdown');
for(var i = 0; i < csv.length; i++) {
var record = csv[i];
var entry = $('<option>').attr('value', record.someProperty);
dropdown.append(entry);
}
};
$.get( https://drive.google.com/open?id=0B87B1QbRsOAXVS14NzBoYnJQNEU, function(data) {
var csv = CSVToArray(data);
renderCSVDropdown(csv);
});
}()); -->
</body>
</html>