说我遇到的问题吧,有两个:
1,驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“PKIX path building failed
遇到如上错误,解决方案见(6条消息) 驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“PKIX path building failed_信管2102谢青海的博客-CSDN博客
2,出现404无法编译的情况
我遇到的就是System.out.printf("%s\t", number);用在jsp程序上了,实际上上jsp无法编译输出system,所以要改成 out.println(“number”)。
接下来贴上我的代码:
<%@ page import="java.sql.*" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
// 加载数据库驱动程序
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
// 连接到数据库
String url = "jdbc:sqlserver://localhost:1433;databaseName=StudentScoreManager2;encrypt=false";
String user = "sa";
String password = "egoist1024";
conn = DriverManager.getConnection(url, user, password);
// 查询数据
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT SNo, SName, SSex FROM StudentInformation");
// 输出查询结果
out.println("<html>");
out.println("<head><title>Student Information</title></head>");
out.println("<body>");
out.println("<h1>Student Information</h1>");
out.println("<table border='1'>");
out.println("<tr><th>SNo</th><th>SName</th><th>SSex</th></tr>");
while (rs.next()) {
out.println("<tr>");
out.println("<td>" + rs.getString("SNo") + "</td>");
out.println("<td>" + rs.getString("SName") + "</td>");
out.println("<td>" + rs.getString("SSex") + "</td>");
out.println("</tr>");
}
out.println("</table>");
out.println("</body>");
out.println("</html>");
} catch (Exception e) {
e.printStackTrace();
} finally {
// 释放资源
if (rs != null) rs.close();
if (stmt != null) stmt.close();
if (conn != null) conn.close();
}
%>
另外值得一提的是:
java程序连接数据库是需要驱动jar的,
jsp等web中,是不需要驱动的。