<%@ page language="java" contentType="text/html; charset=utf-8"   pageEncoding="utf-8"%>
<%@ page  import="java.sql.*" %>
<!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=utf-8">
<title>Insert title here</title>
</head>
<body>
<%
    PreparedStatement ps = null;
    Connection ct = null;
    ResultSet rs = null;
    String url = "jdbc:sqlserver://localhost:1433;databaseName=test";
    String user="sa";  //超级管理员
    String password="sa";  //密码
    try {
        //1.加载驱动
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        System.out.println("加载驱动成功!");
    }catch(Exception e) {
        e.printStackTrace();
        System.out.println("加载驱动失败!");
    }
    try {  
        //2.连接
        ct=DriverManager.getConnection( url,user,password);
        System.out.println("连接数据库成功!");
    }catch(Exception e) {
        e.printStackTrace();
        System.out.println("连接数据库失败!");
    }
    
      
    
     %>
</body>
</html>

 

相关文章:

  • 2022-12-23
  • 2021-11-30
  • 2021-12-10
  • 2021-11-20
  • 2021-12-10
  • 2021-11-20
  • 2021-12-09
  • 2021-09-07
猜你喜欢
  • 2021-11-20
  • 2021-09-13
  • 2021-11-27
  • 2021-11-30
  • 2021-12-10
  • 2021-09-27
相关资源
相似解决方案