forked from rlawrenc/cosc_304
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovinceState.jsp
39 lines (37 loc) · 1.02 KB
/
provinceState.jsp
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
<%@ page import="java.sql.*" %>
<%
String country = request.getParameter("country");
if (country == null)
out.println("INVALID");
else
{
try
{ // Load driver class
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}
catch (java.lang.ClassNotFoundException e)
{
out.println("ClassNotFoundException: " +e);
}
String url = "jdbc:sqlserver://sql04.ok.ubc.ca;databaseName=db_rlawrenc;";
String uid = "rlawrenc";
String pw = "todo";
try ( Connection con = DriverManager.getConnection(url, uid, pw);)
{
String sql = "select stateCode from states where countrycode=?";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setString(1, country);
ResultSet rst = pstmt.executeQuery();
StringBuffer buf = new StringBuffer();
while (rst.next())
{ buf.append(rst.getString(1));
buf.append(',');
}
if (buf.length() > 0)
buf.setLength(buf.length()-1);
out.println(buf.toString());
}
catch (SQLException ex)
{ out.println("INVALID - "+ex); }
}
%>