首先,库文件要包含JDBC的三个jar文件:msbase.jar,mssqlserver.jar,msutil.jar.
password是sa的密码,需要根据具体的sql server配置修改。
运行效果如下:
- <%--
-
Document : Connection
-
Created on : 2012-1-3, 22:32:09
-
Author : Administrator
-
--%>
-
-
<%@page language="java" import="java.util.*" import="java.sql.*" pageEncoding="gb2312" %>
-
<!DOCTYPE html>
-
<html>
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-
<title>JSP连接SQL Server数据库示例</title>
-
</head>
-
<body>
-
<%
-
Connection conn = null;
-
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
-
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=JIMS";
-
String user = "sa";
-
String password = "sa";
-
conn = DriverManager.getConnection(url,user,password);
-
out.println("取得连接");
-
out.print(conn.toString());
-
%>
-
</body>
-
</html>
阅读(14323) | 评论(0) | 转发(0) |