使用eclipse的jsp程序来连接smss数据库

说我遇到的问题吧,有两个:

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中,是不需要驱动的。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值