连接sql server 2005
1 <%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*"%>
2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
3 "http://www.w3.org/TR/html4/loose.dtd">
4
5 <html>
6 <head>
7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
8 <title>JSP Page</title>
9 </head>
10 <body>
11 <%
12 Statement st=null;
13 Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
14 Connection con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=acmen","sa","");
15 st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
16 ResultSet rs=st.executeQuery("select * from stu_1");
17 while(rs.next()){
18 %>
19 <%=rs.getString("userid")%>
20 <%
21 }
22 %>
23 </body>
24 </html>
第一次成功连接上数据库 纪念一下
连接上数据库自己的第一步,加油。。。。