<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<%
Connection conn=null;
try{
String url="jdbc:sqlserver://localhost:1433;databaseName=master";
String user="sa";
String password="123456";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn=DriverManager.getConnection(url,user,password);
out.println("<h2>已通过专用JDBC连接数据库</h2>");
}catch(ClassNotFoundException e){
out.println(e.getMessage());
}catch(SQLException e){
out.println(e.getMessage());
}finally{
try{
if(conn!=null)
conn.close();
}catch(Exception e){}
}
%>
</body>
</html>
JSP连接数据库SQL Server测试代码
最新推荐文章于 2021-01-27 03:13:26 发布