-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjdbc.jsp
42 lines (35 loc) · 910 Bytes
/
jdbc.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
40
41
42
<!--
A JSP file that encapsulates database connections.
Public methods:
- public void getConnection() throws SQLException
- public void closeConnection() throws SQLException
-->
<%@ page import="java.sql.*"%>
<%!
// User id, password, and server information
private String url = "jdbc:sqlserver://cosc304_sqlserver:1433;TrustServerCertificate=True";
private String uid = "sa";
private String pw = "304#sa#pw";
// Connection
private Connection con = null;
%>
<%!
public void getConnection() throws SQLException
{
try
{ // Load driver class
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}
catch (java.lang.ClassNotFoundException e)
{
throw new SQLException("ClassNotFoundException: " +e);
}
con = DriverManager.getConnection(url, uid, pw);
}
public void closeConnection() throws SQLException
{
if (con != null)
con.close();
con = null;
}
%>