JDBC连接SQL server2014代码
<%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
<title>My JSP 'MyJsp.jsp' starting page</title>
</head>
<body>
<% String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
//加载JDBC驱动
String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=JSPTest";
//连接服务器和数据库
String userName = "sa"; //默认用户名
String userPwd = "123456"; //密码
Connection dbConn;
try {
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("Connection Successful!");
//如果连接成功 控制台输出Connection Successful!
} catch (Exception e) {
e.printStackTrace();
}
%>
</body>
</html>